#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  FILE *f;
  if (f = fopen("some.txt", "w"))
    fclose(f);
  if (f = fopen("some.txt", "a")) {
    int i;
    for (i = 0; i < 10; ++i)
      fprintf(f, "%d\n", i);
    fclose(f);
  }
  if (f = fopen("some.txt", "r")) {
    int i;
    while (!feof(f))
      if (fscanf(f, "%d", &i))
        printf("%d\n", i);
    fclose(f);
  }
  if (f = fopen("lorem.txt", "r")) {
    int count = 0;
    while (!feof(f))
      if (fgetc(f) == ' ')
        ++count;
    fclose(f);
    printf("There are %d words in %s.\n", ++count, "lorem.txt");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11a9 <main+0x39>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe50(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1205 <main+0x95>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11fc <main+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe24(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d1 <main+0x61>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdf4(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1286 <main+0x116>
jmp    122b <main+0xbb>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1249 <main+0xd9>
jmp    127d <main+0x10d>
mov    -0x10(%rbp),%rdi
lea    0xdbf(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x0,%rax
je     1278 <main+0x108>
mov    -0x18(%rbp),%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122b <main+0xbb>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd89(%rip),%rdi
lea    0xd7d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1316 <main+0x1a6>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12cc <main+0x15c>
jmp    12ef <main+0x17f>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
movsbl %al,%eax
cmp    $0x20,%eax
jne    12ea <main+0x17a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12ae <main+0x13e>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
lea    0xd18(%rip),%rdi
lea    0xd07(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe82(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1197 <main+0x27>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xe62(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1262 <main+0xf2>
mov    %rax,%rbx
lea    0xe50(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd97(%rip),%rdi
lea    0xda1(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1295 <main+0x125>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     131c <main+0x1ac>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd7a(%rip),%rdi
lea    0xd6e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     130f <main+0x19f>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
mov    $0x1,%ebp
test   %eax,%eax
jne    12f0 <main+0x180>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0x20,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     12d0 <main+0x160>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd21(%rip),%rdi
lea    0xd10(%rip),%rdx
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf0(%rip),%r14
lea    0x4(%rsp),%rbp
lea    0xcde(%rip),%r15
jmp    1350 <main+0x1e0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    128d <main+0x11d>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1050 <fscanf@plt>
test   %rax,%rax
je     1340 <main+0x1d0>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1340 <main+0x1d0>

LLVM IR (-O0):
@.str = [9 x i8] c"some.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [10 x i8] c"lorem.txt\00"
@.str.7 = [27 x i8] c"There are %d words in %s.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32*, i32** %2
%10 = call i32 @fclose(i32* %9)
br label %11
11: ; preds = %8, %0
%12 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %2
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %28
14: ; preds = %11
store i32 0, i32* %3
br label %15
15: ; preds = %22, %14
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 10
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i32*, i32** %2
%20 = load i32, i32* %3
%21 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %15
25: ; preds = %15
%26 = load i32*, i32** %2
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %25, %11
%29 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %29, i32** %2
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %48
31: ; preds = %28
br label %32
32: ; preds = %44, %31
%33 = load i32*, i32** %2
%34 = call i32 @feof(i32* %33)
%35 = icmp ne i32 %34, 0
%36 = xor i1 %35, true
br i1 %36, label %37, label %45
37: ; preds = %32
%38 = load i32*, i32** %2
%39 = call i64 @fscanf(i32* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %4)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %4
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41, %37
br label %32
45: ; preds = %32
%46 = load i32*, i32** %2
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %45, %28
%49 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %49, i32** %2
%50 = icmp ne i32* %49, null
br i1 %50, label %51, label %72
51: ; preds = %48
store i32 0, i32* %5
br label %52
52: ; preds = %65, %51
%53 = load i32*, i32** %2
%54 = call i32 @feof(i32* %53)
%55 = icmp ne i32 %54, 0
%56 = xor i1 %55, true
br i1 %56, label %57, label %66
57: ; preds = %52
%58 = load i32*, i32** %2
%59 = call signext i8 @fgetc(i32* %58)
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 32
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %65
65: ; preds = %62, %57
br label %52
66: ; preds = %52
%67 = load i32*, i32** %2
%68 = call i32 @fclose(i32* %67)
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
%71 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %70, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %72
72: ; preds = %66, %48
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"some.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [10 x i8] c"lorem.txt\00"
@.str.7 = [27 x i8] c"There are %d words in %s.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 @fclose(i32* %2)
br label %6
6: ; preds = %4, %0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %21, label %9
9: ; preds = %6
%10 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%11 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 1)
%12 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 2)
%13 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%14 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 4)
%15 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 5)
%16 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 6)
%17 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 7)
%18 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 8)
%19 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 9)
%20 = tail call i32 @fclose(i32* %7)
br label %21
21: ; preds = %9, %6
%22 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %39, label %24
24: ; preds = %21
%25 = bitcast i32* %1 to i8*
%26 = call i32 @feof(i32* %22)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %24, %34
%29 = call i64 @fscanf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* %1
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %28
%35 = call i32 @feof(i32* %22)
%36 = icmp eq i32 %35, 0
br i1 %36, label %28, label %37
37: ; preds = %34, %24
%38 = call i32 @fclose(i32* %22)
br label %39
39: ; preds = %37, %21
%40 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i32* %40, null
br i1 %41, label %59, label %42
42: ; preds = %39
%43 = call i32 @feof(i32* %40)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %55
45: ; preds = %42, %45
%46 = phi i32 [ %50, %45 ], [ 0, %42 ]
%47 = call signext i8 @fgetc(i32* %40)
%48 = icmp eq i8 %47, 32
%49 = zext i1 %48 to i32
%50 = add nuw nsw i32 %46, %49
%51 = call i32 @feof(i32* %40)
%52 = icmp eq i32 %51, 0
br i1 %52, label %45, label %53
53: ; preds = %45
%54 = add nuw i32 %50, 1
br label %55
55: ; preds = %53, %42
%56 = phi i32 [ 1, %42 ], [ %54, %53 ]
%57 = call i32 @fclose(i32* %40)
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %56, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %59
59: ; preds = %55, %39
ret i32 0
}