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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int getSingleIntegerFromQuery(char *, int, int *);
int /*<<< orphan*/ snprintf(char *, int, char *);
int /*<<< orphan*/ stderr;
int checkVersion() {
  int version;
  char query[1000];
  snprintf(query, sizeof(query), "SELECT VERSION FROM GLOBAL");
  if (getSingleIntegerFromQuery(query, sizeof(query), &version) != 1)
    return 3;
  if (version == 3)
    return 1;
  fprintf(stderr, "Incompatible database version: expected %d, got %d\n", 3,
          version);
  return 2;
}


x86 assembly (clang, -O0):
<checkVersion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3f0,%rsp
lea    -0x3f0(%rbp),%rdi
mov    $0x3e8,%esi
lea    0xeb2(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x3f0(%rbp),%rdi
mov    $0x3e8,%esi
lea    -0x8(%rbp),%rdx
call   1030 <getSingleIntegerFromQuery@plt>
cmp    $0x1,%eax
je     117d <checkVersion+0x4d>
movl   $0x3,-0x4(%rbp)
jmp    11b7 <checkVersion+0x87>
cmpl   $0x3,-0x8(%rbp)
jne    1193 <checkVersion+0x63>
movl   $0x1,-0x4(%rbp)
jmp    11b7 <checkVersion+0x87>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%ecx
lea    0xe75(%rip),%rsi
mov    $0x3,%edx
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkVersion>:
push   %rbx
sub    $0x400,%rsp
lea    0xec1(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1040 <snprintf@plt>
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1030 <getSingleIntegerFromQuery@plt>
mov    %eax,%ecx
mov    $0x3,%eax
cmp    $0x1,%ecx
jne    119c <checkVersion+0x6c>
mov    0xc(%rsp),%ecx
mov    $0x1,%eax
cmp    $0x3,%ecx
je     119c <checkVersion+0x6c>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
mov    $0x3,%edx
call   1050 <fprintf@plt>
mov    $0x2,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"SELECT VERSION FROM GLOBAL\00"
@stderr = global i32 0
@.str.1 = [52 x i8] c"Incompatible database version: expected %d, got %d\0A\00"
define i32 @checkVersion() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 1000, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = call i32 @getSingleIntegerFromQuery(i8* %6, i32 1000, i32* %2)
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 3, i32* %1
br label %18
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 1, i32* %1
br label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = load i32, i32* %2
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %16)
store i32 2, i32* %1
br label %18
18: ; preds = %14, %13, %9
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [27 x i8] c"SELECT VERSION FROM GLOBAL\00"
@stderr = global i32 0
@.str.1 = [52 x i8] c"Incompatible database version: expected %d, got %d\0A\00"
define i32 @checkVersion() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 1000, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @getSingleIntegerFromQuery(i8* %4, i32 1000, i32* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 3
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %9)
br label %14
14: ; preds = %8, %0, %11
%15 = phi i32 [ 2, %11 ], [ 3, %0 ], [ 1, %8 ]
ret i32 %15
}