#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 */
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int mysql_errno(int /*<<< orphan*/ *);
char *mysql_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_fetch_row(int /*<<< orphan*/ *);
scalar_t__ mysql_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *mysql_store_result(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int firstId(MYSQL *connection, char *tableName) {
  MYSQL_RES *result;
  MYSQL_ROW row;
  char *chunk = "SELECT min(id) FROM benchmark.%s";
  char query[100];
  snprintf(query, 100, chunk, tableName);
  if (mysql_query(connection, query)) {
    printf("firstId::Error %u: %s\n", mysql_errno(connection),
           mysql_error(connection));
  }
  result = mysql_store_result(connection);
  row = mysql_fetch_row(result);
  free(result);
  return atoi(row[0]);
}


x86 assembly (clang, -O0):
<firstId>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe56(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x64,%esi
call   1070 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1040 <mysql_query@plt>
cmp    $0x0,%rax
je     120e <firstId+0x7e>
mov    -0x8(%rbp),%rdi
call   1080 <mysql_errno@plt>
mov    %eax,-0x94(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <mysql_error@plt>
mov    -0x94(%rbp),%esi
mov    %rax,%rdx
lea    0xe18(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <mysql_store_result@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <mysql_fetch_row@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<firstId>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%rcx
mov    %rdi,%rbx
lea    0xe5b(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x64,%esi
call   1070 <snprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <mysql_query@plt>
test   %rax,%rax
je     11e8 <firstId+0x58>
mov    %rbx,%rdi
call   1080 <mysql_errno@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <mysql_error@plt>
lea    0xe43(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10b0 <mysql_store_result@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <mysql_fetch_row@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x0(%rbp),%edi
call   10a0 <atoi@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"SELECT min(id) FROM benchmark.%s\00"
@.str.1 = [23 x i8] c"firstId::Error %u: %s\0A\00"
define i32 @firstId(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [100 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %7
%11 = load i8*, i8** %4
%12 = call i32 @snprintf(i8* %9, i32 100, i8* %10, i8* %11)
%13 = load i32*, i32** %3
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%15 = call i64 @mysql_query(i32* %13, i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32*, i32** %3
%19 = call i32 @mysql_errno(i32* %18)
%20 = load i32*, i32** %3
%21 = call i8* @mysql_error(i32* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %21)
br label %23
23: ; preds = %17, %2
%24 = load i32*, i32** %3
%25 = call i32* @mysql_store_result(i32* %24)
store i32* %25, i32** %5
%26 = load i32*, i32** %5
%27 = call i32* @mysql_fetch_row(i32* %26)
store i32* %27, i32** %6
%28 = load i32*, i32** %5
%29 = call i32 @free(i32* %28)
%30 = load i32*, i32** %6
%31 = getelementptr inbounds i32, i32* %30, i64 0
%32 = load i32, i32* %31
%33 = call i32 @atoi(i32 %32)
ret i32 %33
}

LLVM IR (-O2):
@.str = [33 x i8] c"SELECT min(id) FROM benchmark.%s\00"
@.str.1 = [23 x i8] c"firstId::Error %u: %s\0A\00"
define i32 @firstId(i32* %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 100, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %1)
%6 = call i64 @mysql_query(i32* %0, i8* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = call i32 @mysql_errno(i32* %0)
%10 = call i8* @mysql_error(i32* %0)
%11 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %10)
br label %12
12: ; preds = %8, %2
%13 = call i32* @mysql_store_result(i32* %0)
%14 = call i32* @mysql_fetch_row(i32* %13)
%15 = call i32 @free(i32* %13)
%16 = load i32, i32* %14
%17 = call i32 @atoi(i32 %16)
ret i32 %17
}