#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int parse_line(char *, char **, char **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main() {
  FILE *fp;
  char buf[1024];
  char *p;
  fp = fopen("test.ini", "r");
  if (!fp) {
    fprintf(stderr, "fopen file failed\n");
    return -1;
  }
  while (!feof(fp)) {
    p = fgets(buf, 1024, fp);
    if (!p && ferror(fp)) {
      fprintf(stderr, "read file failed\n");
      goto end;
    } else if (!p && feof(fp)) {
      break;
    } else {
      char *key;
      char *value;
      int ret;
      ret = parse_line(buf, &key, &value);
      if (ret < 0) {
        printf("parse line error...\n");
        continue;
      } else {
        printf("key:%s, value:%s\n", key, value);
      }
    }
  }
end:
  if (fp)
    fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe69(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d5 <main+0x55>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1301 <main+0x181>
jmp    11da <main+0x5a>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f9 <main+0x79>
jmp    12e1 <main+0x161>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1250 <main+0xd0>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1250 <main+0xd0>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12e6 <main+0x166>
cmpq   $0x0,-0x418(%rbp)
jne    1276 <main+0xf6>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1276 <main+0xf6>
jmp    12e1 <main+0x161>
lea    -0x410(%rbp),%rdi
lea    -0x420(%rbp),%rsi
lea    -0x428(%rbp),%rdx
call   1090 <parse_line@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jge    12b6 <main+0x136>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11da <main+0x5a>
mov    -0x420(%rbp),%rsi
mov    -0x428(%rbp),%rdx
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d7 <main+0x157>
jmp    12dc <main+0x15c>
jmp    11da <main+0x5a>
jmp    12e6 <main+0x166>
cmpq   $0x0,-0x10(%rbp)
je     12fa <main+0x17a>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xe58(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     11d5 <main+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     1201 <main+0x71>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    11ef <main+0x5f>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
mov    %rsp,%r12
lea    0xe2d(%rip),%r13
lea    0xe14(%rip),%rbp
jmp    1235 <main+0xa5>
xchg   %ax,%ax
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    11c9 <main+0x39>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1268 <main+0xd8>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    128f <main+0xff>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    11c9 <main+0x39>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10a0 <parse_line@plt>
test   %eax,%eax
js     1220 <main+0x90>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1228 <main+0x98>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
call   1080 <fprintf@plt>
jmp    11c9 <main+0x39>

LLVM IR (-O0):
@.str = [9 x i8] c"test.ini\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"fopen file failed\0A\00"
@.str.3 = [18 x i8] c"read file failed\0A\00"
@.str.4 = [21 x i8] c"parse line error...\0A\00"
@.str.5 = [18 x i8] c"key:%s, value:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %63
14: ; preds = %0
br label %15
15: ; preds = %54, %46, %14
%16 = load i32*, i32** %2
%17 = call i64 @feof(i32* %16)
%18 = icmp ne i64 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %55
20: ; preds = %15
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%22 = load i32*, i32** %2
%23 = call i8* @fgets(i8* %21, i32 1024, i32* %22)
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %33, label %26
26: ; preds = %20
%27 = load i32*, i32** %2
%28 = call i64 @ferror(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %56
33: ; preds = %26, %20
%34 = load i8*, i8** %4
%35 = icmp ne i8* %34, null
br i1 %35, label %41, label %36
36: ; preds = %33
%37 = load i32*, i32** %2
%38 = call i64 @feof(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
br label %55
41: ; preds = %36, %33
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%43 = call i32 @parse_line(i8* %42, i8** %5, i8** %6)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %15
48: ; preds = %41
%49 = load i8*, i8** %5
%50 = load i8*, i8** %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %49, i8* %50)
br label %52
52: ; preds = %48
br label %53
53: ; preds = %52
br label %54
54: ; preds = %53
br label %15
55: ; preds = %40, %15
br label %56
56: ; preds = %55, %30
%57 = load i32*, i32** %2
%58 = icmp ne i32* %57, null
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32*, i32** %2
%61 = call i32 @fclose(i32* %60)
br label %62
62: ; preds = %59, %56
store i32 0, i32* %1
br label %63
63: ; preds = %62, %11
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.ini\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"fopen file failed\0A\00"
@.str.3 = [18 x i8] c"read file failed\0A\00"
@.str.5 = [18 x i8] c"key:%s, value:%s\0A\00"
@str = [20 x i8] c"parse line error...\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %0
%8 = call i64 @feof(i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %40
10: ; preds = %7
%11 = bitcast i8** %2 to i8*
%12 = bitcast i8** %3 to i8*
br label %16
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %42
16: ; preds = %10, %37
%17 = call i8* @fgets(i8* %4, i32 1024, i32* %5)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = call i64 @ferror(i32* %5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %40
25: ; preds = %19
%26 = call i64 @feof(i32* %5)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %16, %25
%29 = call i32 @parse_line(i8* %4, i8** %2, i8** %3)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %37
33: ; preds = %28
%34 = load i8*, i8** %2
%35 = load i8*, i8** %3
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %34, i8* %35)
br label %37
37: ; preds = %33, %31
%38 = call i64 @feof(i32* %5)
%39 = icmp eq i64 %38, 0
br i1 %39, label %16, label %40
40: ; preds = %37, %25, %7, %22
%41 = call i32 @fclose(i32* %5)
br label %42
42: ; preds = %40, %13
%43 = phi i32 [ 0, %40 ], [ -1, %13 ]
ret i32 %43
}