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

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ LOG_NOTICE;
int beholddb_decode_version(char const *, int *, int *);
int beholddb_get_param(int /*<<< orphan*/ *, char *, char const **);
int /*<<< orphan*/ beholddb_set_fparam(int /*<<< orphan*/ *, char *, char *,
                                       int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char const *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int version_init(sqlite3 *db) {
  int rc;
  const char *version;
  int major, minor;
  (rc = beholddb_get_param(db, "version", &version)) ||
      (rc = beholddb_decode_version(version, &major, &minor));
  free(version);
  if (rc) {
    return -1;
  }
  if (1 < major) {
    syslog(LOG_ERR, "Metadata format is too new");
    return -1;
  }
  if (1 == major && 0 < minor) {
    syslog(LOG_NOTICE, "Metadata format is newer than the current");
  } else {
    syslog(LOG_INFO, "Set version to %d.%d", 1, 0);
    beholddb_set_fparam(db, "version", "%d.%d", 1, 0);
  }
  switch (major) {
  case 0:;
  case 1:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<version_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <beholddb_get_param@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jne    11a0 <version_init+0x50>
mov    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <beholddb_decode_version@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x14(%rbp)
je     11c2 <version_init+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <version_init+0x14a>
mov    $0x1,%eax
cmp    -0x24(%rbp),%eax
jge    11f3 <version_init+0xa3>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1050 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <version_init+0x14a>
mov    $0x1,%eax
cmp    -0x24(%rbp),%eax
jne    1228 <version_init+0xd8>
xor    %eax,%eax
cmp    -0x28(%rbp),%eax
jge    1228 <version_init+0xd8>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1050 <syslog@plt>
jmp    1265 <version_init+0x115>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1050 <syslog@plt>
mov    -0x10(%rbp),%rdi
lea    0xdaf(%rip),%rsi
lea    0xe04(%rip),%rdx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   1040 <beholddb_set_fparam@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
test   %eax,%eax
je     1289 <version_init+0x139>
jmp    1278 <version_init+0x128>
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
je     128e <version_init+0x13e>
jmp    1293 <version_init+0x143>
jmp    128e <version_init+0x13e>
jmp    1293 <version_init+0x143>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<version_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xe9e(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1070 <beholddb_get_param@plt>
mov    0x8(%rsp),%rdi
test   %eax,%eax
je     1184 <version_init+0x34>
call   1030 <free@plt>
mov    $0xffffffff,%ebp
jmp    1225 <version_init+0xd5>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1060 <beholddb_decode_version@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%ebp
test   %ebx,%ebx
jne    1225 <version_init+0xd5>
mov    0x4(%rsp),%eax
cmp    $0x2,%eax
jl     11c1 <version_init+0x71>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
jmp    11de <version_init+0x8e>
cmp    $0x1,%eax
jne    11e7 <version_init+0x97>
cmpl   $0x0,(%rsp)
jle    11e7 <version_init+0x97>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <syslog@plt>
jmp    1225 <version_init+0xd5>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
xor    %ebp,%ebp
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1050 <syslog@plt>
lea    0xdf2(%rip),%rsi
lea    0xe47(%rip),%rdx
mov    %r14,%rdi
mov    $0x1,%ecx
xor    %r8d,%r8d
call   1040 <beholddb_set_fparam@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"version\00"
@LOG_ERR = global i32 0
@.str.1 = [27 x i8] c"Metadata format is too new\00"
@LOG_NOTICE = global i32 0
@.str.2 = [42 x i8] c"Metadata format is newer than the current\00"
@LOG_INFO = global i32 0
@.str.3 = [21 x i8] c"Set version to %d.%d\00"
@.str.4 = [6 x i8] c"%d.%d\00"
define i32 @version_init(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
%8 = load i32*, i32** %3
%9 = call i32 @beholddb_get_param(i32* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %5)
store i32 %9, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = call i32 @beholddb_decode_version(i8* %12, i32* %6, i32* %7)
store i32 %13, i32* %4
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %11, %1
%16 = phi i1 [ true, %1 ], [ %14, %11 ]
%17 = zext i1 %16 to i32
%18 = load i8*, i8** %5
%19 = call i32 @free(i8* %18)
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 -1, i32* %2
br label %48
23: ; preds = %15
%24 = load i32, i32* %6
%25 = icmp slt i32 1, %24
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @LOG_ERR
%28 = call i32 (i32, i8*, ...) @syslog(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %48
29: ; preds = %23
%30 = load i32, i32* %6
%31 = icmp eq i32 1, %30
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* %7
%34 = icmp slt i32 0, %33
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @LOG_NOTICE
%37 = call i32 (i32, i8*, ...) @syslog(i32 %36, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %43
38: ; preds = %32, %29
%39 = load i32, i32* @LOG_INFO
%40 = call i32 (i32, i8*, ...) @syslog(i32 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 0)
%41 = load i32*, i32** %3
%42 = call i32 @beholddb_set_fparam(i32* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 0)
br label %43
43: ; preds = %38, %35
%44 = load i32, i32* %6
switch i32 %44, label %47 [
i32 0, label %45
i32 1, label %46
]
45: ; preds = %43
br label %46
46: ; preds = %43, %45
br label %47
47: ; preds = %43, %46
store i32 0, i32* %2
br label %48
48: ; preds = %47, %26, %22
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
@.str = [8 x i8] c"version\00"
@LOG_ERR = global i32 0
@.str.1 = [27 x i8] c"Metadata format is too new\00"
@LOG_NOTICE = global i32 0
@.str.2 = [42 x i8] c"Metadata format is newer than the current\00"
@LOG_INFO = global i32 0
@.str.3 = [21 x i8] c"Set version to %d.%d\00"
@.str.4 = [6 x i8] c"%d.%d\00"
define i32 @version_init(i32* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i8** %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32 @beholddb_get_param(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2)
%9 = icmp eq i32 %8, 0
%10 = load i8*, i8** %2
br i1 %9, label %13, label %11
11: ; preds = %1
%12 = call i32 @free(i8* %10)
br label %36
13: ; preds = %1
%14 = call i32 @beholddb_decode_version(i8* %10, i32* %3, i32* %4)
%15 = load i8*, i8** %2
%16 = call i32 @free(i8* %15)
%17 = icmp eq i32 %14, 0
br i1 %17, label %18, label %36
18: ; preds = %13
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @LOG_ERR
%23 = call i32 (i32, i8*, ...) @syslog(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %36
24: ; preds = %18
%25 = icmp eq i32 %19, 1
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 0
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* @LOG_NOTICE
%31 = call i32 (i32, i8*, ...) @syslog(i32 %30, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %36
32: ; preds = %24
%33 = load i32, i32* @LOG_INFO
%34 = call i32 (i32, i8*, ...) @syslog(i32 %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 0)
%35 = call i32 @beholddb_set_fparam(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 0)
br label %36
36: ; preds = %11, %29, %32, %13, %21
%37 = phi i32 [ -1, %21 ], [ -1, %13 ], [ 0, %32 ], [ 0, %29 ], [ -1, %11 ]
ret i32 %37
}