#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*/ *MYSQL_ROW;
typedef int /*<<< orphan*/ MYSQL_RES;
typedef int /*<<< orphan*/ MYSQL;

/* Variables and functions */
unsigned int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ check_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ *do_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *mysql_fetch_row(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_free_result(int /*<<< orphan*/ *);
int mysql_num_rows(int /*<<< orphan*/ *);
unsigned int get_tick(MYSQL *mysql) {
  MYSQL_RES *res;
  MYSQL_ROW row;
  unsigned int retval = 0;
  res = do_query(mysql, "SELECT tick FROM general");
  if (res && mysql_num_rows(res) == 1) {
    row = mysql_fetch_row(res);
    retval = atoi(row[0]);
    mysql_free_result(res);
  }
  check_error(mysql);
  return retval;
}


x86 assembly (clang, -O0):
<get_tick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1040 <do_query@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c8 <get_tick+0x68>
mov    -0x10(%rbp),%rdi
call   1080 <mysql_num_rows@plt>
cmp    $0x1,%eax
jne    11c8 <get_tick+0x68>
mov    -0x10(%rbp),%rdi
call   1030 <mysql_fetch_row@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <mysql_free_result@plt>
mov    -0x8(%rbp),%rdi
call   1050 <check_error@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tick>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1040 <do_query@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11a3 <get_tick+0x43>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <mysql_num_rows@plt>
cmp    $0x1,%eax
jne    11a3 <get_tick+0x43>
mov    %rbx,%rdi
call   1030 <mysql_fetch_row@plt>
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <mysql_free_result@plt>
mov    %r14,%rdi
call   1050 <check_error@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"SELECT tick FROM general\00"
define i32 @get_tick(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %5
%6 = load i32*, i32** %2
%7 = call i32* @do_query(i32* %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %23
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i32 @mysql_num_rows(i32* %11)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = call i32* @mysql_fetch_row(i32* %15)
store i32* %16, i32** %4
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = call i32 @atoi(i32 %19)
store i32 %20, i32* %5
%21 = load i32*, i32** %3
%22 = call i32 @mysql_free_result(i32* %21)
br label %23
23: ; preds = %14, %10, %1
%24 = load i32*, i32** %2
%25 = call i32 @check_error(i32* %24)
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@.str = [25 x i8] c"SELECT tick FROM general\00"
define i32 @get_tick(i32* %0) {
%2 = tail call i32* @do_query(i32* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @mysql_num_rows(i32* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32* @mysql_fetch_row(i32* %2)
%9 = load i32, i32* %8
%10 = tail call i32 @atoi(i32 %9)
%11 = tail call i32 @mysql_free_result(i32* %2)
br label %12
12: ; preds = %7, %4, %1
%13 = phi i32 [ %10, %7 ], [ 0, %4 ], [ 0, %1 ]
%14 = tail call i32 @check_error(i32* %0)
ret i32 %13
}