#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ beginTrans(int /*<<< orphan*/);
int /*<<< orphan*/ commitTrans();
int getDbVersion();
int /*<<< orphan*/ logMsg(int, char *, int);
int /*<<< orphan*/ rollbackTrans();
int upgrade2();
int upgrade3();
int upgrade4();
int upgrade5();
int upgrade6();
int upgrade7();
int upgradeTo(int level) {
  assert(getDbVersion() == level - 1);
  int status = 0;
  beginTrans(0);
  switch (level) {
  case 2:
    status = upgrade2();
    break;
  case 3:
    status = upgrade3();
    break;
  case 4:
    status = upgrade4();
    break;
  case 5:
    status = upgrade5();
    break;
  case 6:
    status = upgrade6();
    break;
  case 7:
    status = upgrade7();
    break;
  default:
    assert(0);
  }
  if (status == 1) {
    commitTrans();
    logMsg(2, "Database level upgraded to %d.", level);
  } else {
    rollbackTrans();
  }
  return status;
}


x86 assembly (clang, -O0):
<upgradeTo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,-0x14(%rbp)
call   1090 <getDbVersion@plt>
mov    -0x4(%rbp),%ecx
add    $0xffffffff,%ecx
sub    %ecx,%eax
sete   %al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    -0x14(%rbp),%edi
movl   $0x0,-0x8(%rbp)
call   1080 <beginTrans@plt>
mov    -0x4(%rbp),%eax
add    $0xfffffffe,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x5,%eax
ja     127a <upgradeTo+0xba>
mov    -0x10(%rbp),%rax
lea    0xde9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1060 <upgrade2@plt>
mov    %eax,-0x8(%rbp)
jmp    1281 <upgradeTo+0xc1>
mov    $0x0,%al
call   10c0 <upgrade3@plt>
mov    %eax,-0x8(%rbp)
jmp    1281 <upgradeTo+0xc1>
mov    $0x0,%al
call   1050 <upgrade4@plt>
mov    %eax,-0x8(%rbp)
jmp    1281 <upgradeTo+0xc1>
mov    $0x0,%al
call   10e0 <upgrade5@plt>
mov    %eax,-0x8(%rbp)
jmp    1281 <upgradeTo+0xc1>
mov    $0x0,%al
call   1070 <upgrade6@plt>
mov    %eax,-0x8(%rbp)
jmp    1281 <upgradeTo+0xc1>
mov    $0x0,%al
call   10d0 <upgrade7@plt>
mov    %eax,-0x8(%rbp)
jmp    1281 <upgradeTo+0xc1>
xor    %edi,%edi
call   10b0 <assert@plt>
cmpl   $0x1,-0x8(%rbp)
jne    12ab <upgradeTo+0xeb>
mov    $0x0,%al
call   1030 <commitTrans@plt>
mov    -0x4(%rbp),%edx
mov    $0x2,%edi
lea    0xd77(%rip),%rsi
call   10a0 <logMsg@plt>
jmp    12b2 <upgradeTo+0xf2>
mov    $0x0,%al
call   1040 <rollbackTrans@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upgradeTo>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1090 <getDbVersion@plt>
lea    -0x1(%rbx),%ecx
xor    %edi,%edi
cmp    %ecx,%eax
sete   %dil
call   10b0 <assert@plt>
xor    %edi,%edi
call   1080 <beginTrans@plt>
lea    -0x2(%rbx),%eax
cmp    $0x5,%eax
ja     1206 <upgradeTo+0x46>
lea    0xe0c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
call   1060 <upgrade2@plt>
jmp    123a <upgradeTo+0x7a>
xor    %edi,%edi
call   10b0 <assert@plt>
jmp    1262 <upgradeTo+0xa2>
xor    %eax,%eax
call   10c0 <upgrade3@plt>
jmp    123a <upgradeTo+0x7a>
xor    %eax,%eax
call   1050 <upgrade4@plt>
jmp    123a <upgradeTo+0x7a>
xor    %eax,%eax
call   10e0 <upgrade5@plt>
jmp    123a <upgradeTo+0x7a>
xor    %eax,%eax
call   1070 <upgrade6@plt>
jmp    123a <upgradeTo+0x7a>
xor    %eax,%eax
call   10d0 <upgrade7@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
jne    1262 <upgradeTo+0xa2>
xor    %eax,%eax
call   1030 <commitTrans@plt>
lea    0xdc9(%rip),%rsi
mov    $0x2,%edi
mov    %ebx,%edx
call   10a0 <logMsg@plt>
mov    $0x1,%ebp
jmp    1269 <upgradeTo+0xa9>
xor    %eax,%eax
call   1040 <rollbackTrans@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Database level upgraded to %d.\00"
define i32 @upgradeTo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @getDbVersion()
%5 = load i32, i32* %2
%6 = sub nsw i32 %5, 1
%7 = icmp eq i32 %4, %6
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
store i32 0, i32* %3
%10 = call i32 @beginTrans(i32 0)
%11 = load i32, i32* %2
switch i32 %11, label %24 [
i32 2, label %12
i32 3, label %14
i32 4, label %16
i32 5, label %18
i32 6, label %20
i32 7, label %22
]
12: ; preds = %1
%13 = call i32 (...) @upgrade2()
store i32 %13, i32* %3
br label %26
14: ; preds = %1
%15 = call i32 (...) @upgrade3()
store i32 %15, i32* %3
br label %26
16: ; preds = %1
%17 = call i32 (...) @upgrade4()
store i32 %17, i32* %3
br label %26
18: ; preds = %1
%19 = call i32 (...) @upgrade5()
store i32 %19, i32* %3
br label %26
20: ; preds = %1
%21 = call i32 (...) @upgrade6()
store i32 %21, i32* %3
br label %26
22: ; preds = %1
%23 = call i32 (...) @upgrade7()
store i32 %23, i32* %3
br label %26
24: ; preds = %1
%25 = call i32 @assert(i32 0)
br label %26
26: ; preds = %24, %22, %20, %18, %16, %14, %12
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = call i32 (...) @commitTrans()
%31 = load i32, i32* %2
%32 = call i32 @logMsg(i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %35
33: ; preds = %26
%34 = call i32 (...) @rollbackTrans()
br label %35
35: ; preds = %33, %29
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [31 x i8] c"Database level upgraded to %d.\00"
define i32 @upgradeTo(i32 %0) {
%2 = tail call i32 (...) @getDbVersion()
%3 = add nsw i32 %0, -1
%4 = icmp eq i32 %2, %3
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @beginTrans(i32 0)
switch i32 %0, label %20 [
i32 2, label %8
i32 3, label %10
i32 4, label %12
i32 5, label %14
i32 6, label %16
i32 7, label %18
]
8: ; preds = %1
%9 = tail call i32 (...) @upgrade2()
br label %22
10: ; preds = %1
%11 = tail call i32 (...) @upgrade3()
br label %22
12: ; preds = %1
%13 = tail call i32 (...) @upgrade4()
br label %22
14: ; preds = %1
%15 = tail call i32 (...) @upgrade5()
br label %22
16: ; preds = %1
%17 = tail call i32 (...) @upgrade6()
br label %22
18: ; preds = %1
%19 = tail call i32 (...) @upgrade7()
br label %22
20: ; preds = %1
%21 = tail call i32 @assert(i32 0)
br label %28
22: ; preds = %18, %16, %14, %12, %10, %8
%23 = phi i32 [ %19, %18 ], [ %17, %16 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ]
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i32 (...) @commitTrans()
%27 = tail call i32 @logMsg(i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %31
28: ; preds = %20, %22
%29 = phi i32 [ 0, %20 ], [ %23, %22 ]
%30 = tail call i32 (...) @rollbackTrans()
br label %31
31: ; preds = %28, %25
%32 = phi i32 [ %29, %28 ], [ 1, %25 ]
ret i32 %32
}