#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int read_data_sum() {
  int sum;
  FILE *fpin;
  fpin = fopen("data/select.db", "r");
  if (fpin == NULL) {
    printf("error	:	files %s can not open !\n", "data/select.db");
    exit(1);
  }
  printf("read data num from %s ...\n", "data/select.db");
  for (sum = 0; !feof(fpin);) {
    if ('^' == fgetc(fpin))
      sum++;
  }
  fclose(fpin);
  printf("data num are %d \n", sum);
  return sum;
}


x86 assembly (clang, -O0):
<read_data_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a9 <read_data_sum+0x49>
lea    0xe80(%rip),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe82(%rip),%rdi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e3 <read_data_sum+0x83>
jmp    120a <read_data_sum+0xaa>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
movsbl %al,%ecx
mov    $0x5e,%eax
cmp    %ecx,%eax
jne    1205 <read_data_sum+0xa5>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <read_data_sum+0x65>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data_sum>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ef <read_data_sum+0x8f>
mov    %rax,%r14
lea    0xeac(%rip),%rdi
lea    0xe73(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11cd <read_data_sum+0x6d>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0x5e,%al
sete   %cl
add    %ecx,%ebx
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11b0 <read_data_sum+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xe71(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1b(%rip),%rdi
lea    0xe03(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"data/select.db\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"error\09:\09files %s can not open !\0A\00"
@.str.3 = [27 x i8] c"read data num from %s ...\0A\00"
@.str.4 = [18 x i8] c"data num are %d \0A\00"
define i32 @read_data_sum() {
%1 = alloca i32
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %11
11: ; preds = %24, %9
%12 = load i32*, i32** %2
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %25
16: ; preds = %11
%17 = load i32*, i32** %2
%18 = call signext i8 @fgetc(i32* %17)
%19 = sext i8 %18 to i32
%20 = icmp eq i32 94, %19
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
store i32 %23, i32* %1
br label %24
24: ; preds = %21, %16
br label %11
25: ; preds = %11
%26 = load i32*, i32** %2
%27 = call i32 @fclose(i32* %26)
%28 = load i32, i32* %1
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [15 x i8] c"data/select.db\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"error\09:\09files %s can not open !\0A\00"
@.str.3 = [27 x i8] c"read data num from %s ...\0A\00"
@.str.4 = [18 x i8] c"data num are %d \0A\00"
define i32 @read_data_sum() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @feof(i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %6, %10
%11 = phi i32 [ %15, %10 ], [ 0, %6 ]
%12 = tail call signext i8 @fgetc(i32* %1)
%13 = icmp eq i8 %12, 94
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %11, %14
%16 = tail call i32 @feof(i32* %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %10, label %18
18: ; preds = %10, %6
%19 = phi i32 [ 0, %6 ], [ %15, %10 ]
%20 = tail call i32 @fclose(i32* %1)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %19)
ret i32 %19
}