#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 */

/* Variables and functions */
int db_begin();
int db_commit();
int db_connect();
int db_disconnect();
int db_rollback();
int input_file(char *, char *);
int /*<<< orphan*/ log_fatal(char *, int, char *);
int /*<<< orphan*/ log_info(char *, int, char *);
int /*<<< orphan*/ log_warn(char *, int, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char *name;
  char *file;
  int ret;
  int fail = 0;
  char *state;
  if (argc != 3) {
    printf("Brain training\n");
    printf("Usage: %s <name> <filename>\n", argv[0]);
    return 1;
  }
  name = argv[1];
  file = argv[2];
  state = "db_connect";
  ret = db_connect();
  if (ret)
    goto fail;
  else
    log_info("train", ret, state);
  state = "db_begin";
  ret = db_begin();
  if (ret)
    goto fail;
  else
    log_info("train", ret, state);
  state = "input_file";
  ret = input_file(name, file);
  if (ret) {
    log_warn("train", ret, state);
    fail = 1;
  } else
    log_info("train", ret, state);
  if (fail) {
    state = "db_rollback";
    ret = db_rollback();
    if (ret)
      goto fail;
    else
      log_info("train", ret, state);
  } else {
    state = "db_commit";
    ret = db_commit();
    if (ret)
      goto fail;
    else
      log_info("train", ret, state);
  }
  state = "db_disconnect";
  ret = db_disconnect();
  if (ret)
    goto fail;
  else
    log_info("train", ret, state);
  return 0;
fail:
  log_fatal("train", ret, state);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f6 <main+0x56>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b2 <main+0x212>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    0xe18(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   10b0 <db_connect@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1232 <main+0x92>
jmp    1398 <main+0x1f8>
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xdf8(%rip),%rdi
call   1040 <log_info@plt>
lea    0xdf2(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <db_begin@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1269 <main+0xc9>
jmp    1398 <main+0x1f8>
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xdc1(%rip),%rdi
call   1040 <log_info@plt>
lea    0xdc4(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10a0 <input_file@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12c0 <main+0x120>
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xd89(%rip),%rdi
call   1080 <log_warn@plt>
movl   $0x1,-0x28(%rbp)
jmp    12d3 <main+0x133>
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xd6a(%rip),%rdi
call   1040 <log_info@plt>
cmpl   $0x0,-0x28(%rbp)
je     1319 <main+0x179>
lea    0xd6e(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1090 <db_rollback@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1301 <main+0x161>
jmp    1398 <main+0x1f8>
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xd29(%rip),%rdi
call   1040 <log_info@plt>
jmp    1355 <main+0x1b5>
lea    0xd3e(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1070 <db_commit@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     133d <main+0x19d>
jmp    1398 <main+0x1f8>
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xced(%rip),%rdi
call   1040 <log_info@plt>
jmp    1355 <main+0x1b5>
lea    0xd0c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <db_disconnect@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1379 <main+0x1d9>
jmp    1398 <main+0x1f8>
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xcb1(%rip),%rdi
call   1040 <log_info@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b2 <main+0x212>
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xc92(%rip),%rdi
call   10c0 <log_fatal@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11dc <main+0x2c>
mov    0x8(%rbx),%r15
mov    0x10(%rbx),%r14
xor    %eax,%eax
call   10c0 <db_connect@plt>
test   %eax,%eax
je     11fe <main+0x4e>
lea    0xe46(%rip),%rdx
jmp    12b2 <main+0x102>
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%rsi
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12c0 <main+0x110>
lea    0xe23(%rip),%rdi
lea    0xe11(%rip),%rdx
xor    %esi,%esi
call   1050 <log_info@plt>
xor    %eax,%eax
call   1030 <db_begin@plt>
test   %eax,%eax
je     122a <main+0x7a>
lea    0xe09(%rip),%rdx
jmp    12b2 <main+0x102>
lea    0xdf7(%rip),%rdi
lea    0xdf6(%rip),%rdx
xor    %esi,%esi
call   1050 <log_info@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10b0 <input_file@plt>
lea    0xdd7(%rip),%rdi
lea    0xddf(%rip),%rdx
test   %eax,%eax
je     1277 <main+0xc7>
mov    %eax,%esi
call   1090 <log_warn@plt>
xor    %eax,%eax
call   10a0 <db_rollback@plt>
lea    0xdd1(%rip),%rdx
test   %eax,%eax
jne    12b2 <main+0x102>
jmp    1290 <main+0xe0>
xor    %esi,%esi
call   1050 <log_info@plt>
xor    %eax,%eax
call   1080 <db_commit@plt>
lea    0xdc2(%rip),%rdx
test   %eax,%eax
jne    12b2 <main+0x102>
lea    0xd91(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1050 <log_info@plt>
xor    %eax,%eax
call   1070 <db_disconnect@plt>
test   %eax,%eax
je     12cd <main+0x11d>
lea    0xda6(%rip),%rdx
lea    0xd6f(%rip),%rdi
mov    %eax,%esi
call   10d0 <log_fatal@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd54(%rip),%rdi
lea    0xd7d(%rip),%rdx
xor    %esi,%esi
call   1050 <log_info@plt>
jmp    12c5 <main+0x115>

LLVM IR (-O0):
@.str = [16 x i8] c"Brain training\0A\00"
@.str.1 = [29 x i8] c"Usage: %s <name> <filename>\0A\00"
@.str.2 = [11 x i8] c"db_connect\00"
@.str.3 = [6 x i8] c"train\00"
@.str.4 = [9 x i8] c"db_begin\00"
@.str.5 = [11 x i8] c"input_file\00"
@.str.6 = [12 x i8] c"db_rollback\00"
@.str.7 = [10 x i8] c"db_commit\00"
@.str.8 = [14 x i8] c"db_disconnect\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %94
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
store i8* %25, i8** %7
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %10
%26 = call i32 (...) @db_connect()
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %19
br label %90
30: ; preds = %19
%31 = load i32, i32* %8
%32 = load i8*, i8** %10
%33 = call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %31, i8* %32)
br label %34
34: ; preds = %30
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8** %10
%35 = call i32 (...) @db_begin()
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
br label %90
39: ; preds = %34
%40 = load i32, i32* %8
%41 = load i8*, i8** %10
%42 = call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %40, i8* %41)
br label %43
43: ; preds = %39
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8** %10
%44 = load i8*, i8** %6
%45 = load i8*, i8** %7
%46 = call i32 @input_file(i8* %44, i8* %45)
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %43
%50 = load i32, i32* %8
%51 = load i8*, i8** %10
%52 = call i32 @log_warn(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %50, i8* %51)
store i32 1, i32* %9
br label %57
53: ; preds = %43
%54 = load i32, i32* %8
%55 = load i8*, i8** %10
%56 = call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %54, i8* %55)
br label %57
57: ; preds = %53, %49
%58 = load i32, i32* %9
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %70
60: ; preds = %57
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8** %10
%61 = call i32 (...) @db_rollback()
store i32 %61, i32* %8
%62 = load i32, i32* %8
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %60
br label %90
65: ; preds = %60
%66 = load i32, i32* %8
%67 = load i8*, i8** %10
%68 = call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %66, i8* %67)
br label %69
69: ; preds = %65
br label %80
70: ; preds = %57
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8** %10
%71 = call i32 (...) @db_commit()
store i32 %71, i32* %8
%72 = load i32, i32* %8
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %70
br label %90
75: ; preds = %70
%76 = load i32, i32* %8
%77 = load i8*, i8** %10
%78 = call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %76, i8* %77)
br label %79
79: ; preds = %75
br label %80
80: ; preds = %79, %69
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %10
%81 = call i32 (...) @db_disconnect()
store i32 %81, i32* %8
%82 = load i32, i32* %8
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %80
br label %90
85: ; preds = %80
%86 = load i32, i32* %8
%87 = load i8*, i8** %10
%88 = call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %86, i8* %87)
br label %89
89: ; preds = %85
store i32 0, i32* %3
br label %94
90: ; preds = %84, %74, %64, %38, %29
%91 = load i32, i32* %8
%92 = load i8*, i8** %10
%93 = call i32 @log_fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %91, i8* %92)
store i32 1, i32* %3
br label %94
94: ; preds = %90, %89, %13
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str.1 = [29 x i8] c"Usage: %s <name> <filename>\0A\00"
@.str.2 = [11 x i8] c"db_connect\00"
@.str.3 = [6 x i8] c"train\00"
@.str.4 = [9 x i8] c"db_begin\00"
@.str.5 = [11 x i8] c"input_file\00"
@.str.6 = [12 x i8] c"db_rollback\00"
@.str.7 = [10 x i8] c"db_commit\00"
@.str.8 = [14 x i8] c"db_disconnect\00"
@str = [15 x i8] c"Brain training\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %42
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 (...) @db_connect()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %38
15: ; preds = %8
%16 = tail call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 (...) @db_begin()
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = tail call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @input_file(i8* %10, i8* %12)
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = tail call i32 @log_warn(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%25 = tail call i32 (...) @db_rollback()
%26 = icmp eq i32 %25, 0
br i1 %26, label %31, label %38
27: ; preds = %19
%28 = tail call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%29 = tail call i32 (...) @db_commit()
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %27, %23
%32 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), %23 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), %27 ]
%33 = tail call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 0, i8* %32)
%34 = tail call i32 (...) @db_disconnect()
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = tail call i32 @log_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %42
38: ; preds = %31, %27, %23, %15, %8
%39 = phi i32 [ %13, %8 ], [ %17, %15 ], [ %25, %23 ], [ %34, %31 ], [ %29, %27 ]
%40 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %15 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), %23 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), %31 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), %27 ]
%41 = tail call i32 @log_fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %39, i8* %40)
br label %42
42: ; preds = %38, %36, %4
%43 = phi i32 [ 1, %4 ], [ 1, %38 ], [ 0, %36 ]
ret i32 %43
}