#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*/ *Sfopen(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int GetTotalNumber(void) {
  FILE *fp_primer_number;
  int count = 0;
  int temp;
  fp_primer_number = Sfopen("primer_number.txt");
  while (fscanf(fp_primer_number, "%d", &temp) > 0) {
    count++;
  }
  fclose(fp_primer_number);
  return count;
}


x86 assembly (clang, -O0):
<GetTotalNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeba(%rip),%rdi
call   1050 <Sfopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb8(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x0,%rax
jle    117b <GetTotalNumber+0x4b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <GetTotalNumber+0x1f>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetTotalNumber>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
call   1050 <Sfopen@plt>
mov    %rax,%r14
mov    $0xffffffff,%ebx
lea    0xebf(%rip),%r15
lea    0x4(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
add    $0x1,%ebx
test   %rax,%rax
jg     1160 <GetTotalNumber+0x30>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"primer_number.txt\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @GetTotalNumber() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
%4 = call i32* @Sfopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %1
br label %5
5: ; preds = %9, %0
%6 = load i32*, i32** %1
%7 = call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 1
store i32 %11, i32* %2
br label %5
12: ; preds = %5
%13 = load i32*, i32** %1
%14 = call i32 @fclose(i32* %13)
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
@.str = [18 x i8] c"primer_number.txt\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @GetTotalNumber() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @Sfopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = phi i32 [ 0, %0 ], [ %8, %4 ]
%6 = call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = icmp sgt i64 %6, 0
%8 = add nuw nsw i32 %5, 1
br i1 %7, label %4, label %9
9: ; preds = %4
%10 = call i32 @fclose(i32* %3)
ret i32 %5
}