#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 */
scalar_t__ check_line(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int lines_in_file(char *fname) {
  register int l;
  FILE *fp, *fopen();
  fp = fopen(fname, "r");
  if (!fp) {
    printf("file %s does not exist\n", fname);
    exit(-1);
  }
  l = 0;
  while (check_line(fp))
    l++;
  fclose(fp);
  return l;
}


x86 assembly (clang, -O0):
<lines_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1195 <lines_in_file+0x45>
mov    -0x8(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <check_line@plt>
cmp    $0x0,%rax
je     11bd <lines_in_file+0x6d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119c <lines_in_file+0x4c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lines_in_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1191 <lines_in_file+0x41>
mov    %rax,%rbx
mov    $0xffffffff,%ebp
nop
mov    %rbx,%rdi
call   1050 <check_line@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1170 <lines_in_file+0x20>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe6a(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"file %s does not exist\0A\00"
define i32 @lines_in_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %1
store i32 0, i32* %3
br label %14
14: ; preds = %18, %13
%15 = load i32*, i32** %4
%16 = call i64 @check_line(i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %14
21: ; preds = %14
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"file %s does not exist\0A\00"
define i32 @lines_in_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %1, %7
%8 = phi i32 [ %11, %7 ], [ 0, %1 ]
%9 = tail call i64 @check_line(i32* %2)
%10 = icmp eq i64 %9, 0
%11 = add nuw nsw i32 %8, 1
br i1 %10, label %12, label %7
12: ; preds = %7
%13 = tail call i32 @fclose(i32* %2)
ret i32 %8
}