#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long long int get_num_ints(char *filename) {
  FILE *fd;
  char number[50];
  long long int num = 0;
  if ((fd = fopen(filename, "r")) != NULL) {
    while (fgets(number, 50, fd) != NULL) {
      num++;
    }
    fclose(fd);
  }
  return num;
}


x86 assembly (clang, -O0):
<get_num_ints>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     119d <get_num_ints+0x6d>
jmp    1167 <get_num_ints+0x37>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x32,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1194 <get_num_ints+0x64>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1167 <get_num_ints+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x58(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num_ints>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1183 <get_num_ints+0x53>
mov    %rax,%r14
mov    $0xffffffffffffffff,%rbx
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x32,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <get_num_ints+0x30>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    1185 <get_num_ints+0x55>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i64 @get_num_ints(i8* nocapture %0) {
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %13, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %10, %6 ], [ 0, %1 ]
%8 = call i32* @fgets(i8* %3, i32 50, i32* %4)
%9 = icmp eq i32* %8, null
%10 = add nuw nsw i64 %7, 1
br i1 %9, label %11, label %6
11: ; preds = %6
%12 = call i32 @fclose(i32* %4)
br label %13
13: ; preds = %11, %1
%14 = phi i64 [ %7, %11 ], [ 0, %1 ]
ret i64 %14
}