#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fail_open(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_file(char *);
int /*<<< orphan*/ printf(char *, ...);
int parse_external_sources(char *filename) {
  FILE *f;
  char buf[1024], *p;
  int n;
  if ((f = open_file(filename)) == NULL)
    return fail_open(filename);
  while (!feof(f)) {
    p = fgets(buf, 1024, f);
    if (p != NULL)
      printf("in:%s", buf);
    else
      printf("end\n");
  }
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<parse_external_sources>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <open_file@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1197 <parse_external_sources+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <fail_open@plt>
mov    %eax,-0x4(%rbp)
jmp    1221 <parse_external_sources+0xc1>
jmp    119c <parse_external_sources+0x3c>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ba <parse_external_sources+0x5a>
jmp    1211 <parse_external_sources+0xb1>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     11fe <parse_external_sources+0x9e>
lea    -0x420(%rbp),%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    120c <parse_external_sources+0xac>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    119c <parse_external_sources+0x3c>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_external_sources>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
call   1060 <open_file@plt>
test   %rax,%rax
je     11b6 <parse_external_sources+0x46>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     11cc <parse_external_sources+0x5c>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fail_open@plt>
mov    %rsp,%r14
lea    0xe30(%rip),%r15
lea    0xe23(%rip),%r12
jmp    11f4 <parse_external_sources+0x84>
nop
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    119a <parse_external_sources+0x2a>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     11e0 <parse_external_sources+0x70>
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    11e8 <parse_external_sources+0x78>

LLVM IR (-O0):
@.str = [6 x i8] c"in:%s\00"
@.str.1 = [5 x i8] c"end\0A\00"
define i32 @parse_external_sources(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @open_file(i8* %8)
store i32* %9, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @fail_open(i8* %12)
store i32 %13, i32* %2
br label %35
14: ; preds = %1
br label %15
15: ; preds = %31, %14
%16 = load i32*, i32** %4
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %32
20: ; preds = %15
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = load i32*, i32** %4
%23 = call i8* @fgets(i8* %21, i32 1024, i32* %22)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %31
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
br label %15
32: ; preds = %15
%33 = load i32*, i32** %4
%34 = call i32 @fclose(i32* %33)
store i32 1, i32* %2
br label %35
35: ; preds = %32, %11
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [6 x i8] c"in:%s\00"
@str = [4 x i8] c"end\00"
define i32 @parse_external_sources(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @open_file(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %21
9: ; preds = %1
%10 = tail call i32 @fail_open(i8* %0)
br label %23
11: ; preds = %6, %18
%12 = call i8* @fgets(i8* %3, i32 1024, i32* %4)
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %18
16: ; preds = %11
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = call i32 @feof(i32* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %11, label %21
21: ; preds = %18, %6
%22 = call i32 @fclose(i32* %4)
br label %23
23: ; preds = %21, %9
%24 = phi i32 [ %10, %9 ], [ 1, %21 ]
ret i32 %24
}