#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;
  file = fopen("test65.dat", "r");
  if (file == 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)
cmpq   $0x0,-0x98(%rbp)
jne    11d1 <main+0x61>
lea    0xe4b(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    11d6 <main+0x66>
lea    -0x80(%rbp),%rdi
mov    -0x98(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1233 <main+0xc3>
lea    -0x8a(%rbp),%rdi
mov    -0x9c(%rbp),%ecx
mov    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
mov    $0xa,%esi
lea    0xe01(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x80(%rbp),%rdi
lea    -0x8a(%rbp),%rsi
call   1060 <add_to_cache@plt>
jmp    11d6 <main+0x66>
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 = load i32*, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %8
%20 = call i32* @fgets(i8* %18, i32 100, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 1
store i32 %25, i32* %9
%26 = call i32 @snprintf(i8* %23, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%29 = call i32 @add_to_cache(i8* %27, i8* %28)
br label %17
30: ; preds = %17
%31 = load i32*, i32** %8
%32 = call i32 @fclose(i32* %31)
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
}