#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*/ nbuf;
typedef int /*<<< orphan*/ linebuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ add_to_cache(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char linebuf[100], nbuf[10];
  FILE *file;
  int i = 0;
  if ((file = fopen("test65.dat", "r")) == NULL) {
    perror("can't open: ");
    exit(-1);
  }
  while (fgets(linebuf, sizeof(linebuf), file) != NULL) {
    snprintf(nbuf, sizeof(nbuf), "%u", i++);
    add_to_cache(linebuf, nbuf);
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x9c(%rbp)
lea    0xe66(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    11cd <main+0x5d>
lea    0xe4f(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    11d2 <main+0x62>
lea    -0x80(%rbp),%rdi
mov    -0x98(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     122f <main+0xbf>
lea    -0x8a(%rbp),%rdi
mov    -0x9c(%rbp),%ecx
mov    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
mov    $0xa,%esi
lea    0xe05(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x80(%rbp),%rdi
lea    -0x8a(%rbp),%rsi
call   1060 <add_to_cache@plt>
jmp    11d2 <main+0x62>
mov    -0x98(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
lea    0xe7a(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     121f <main+0xaf>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1205 <main+0x95>
xor    %ecx,%ecx
lea    0xe5c(%rip),%r14
lea    0x6(%rsp),%r12
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%ebp
mov    %r12,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <add_to_cache@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
mov    %ebp,%ecx
test   %rax,%rax
jne    11d0 <main+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde7(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"test65.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"can't open: \00"
@.str.3 = [3 x i8] c"%u\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca [10 x i8]
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%10 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
br label %16
16: ; preds = %21, %15
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %8
%19 = call i32* @fgets(i8* %17, i32 100, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
store i32 %24, i32* %9
%25 = call i32 @snprintf(i8* %22, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%28 = call i32 @add_to_cache(i8* %26, i8* %27)
br label %16
29: ; preds = %16
%30 = load i32*, i32** %8
%31 = call i32 @fclose(i32* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"test65.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"can't open: \00"
@.str.3 = [3 x i8] c"%u\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32* @fgets(i8* %5, i32 100, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %22, label %15
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %9, %15
%16 = phi i32 [ %17, %15 ], [ 0, %9 ]
%17 = add nuw nsw i32 %16, 1
%18 = call i32 @snprintf(i8* %6, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%19 = call i32 @add_to_cache(i8* %5, i8* %6)
%20 = call i32* @fgets(i8* %5, i32 100, i32* %7)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %15
22: ; preds = %15, %9
%23 = call i32 @fclose(i32* %7)
ret i32 0
}