#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 */
struct timeval {
  int dummy;
};
typedef int /*<<< orphan*/ MYSQL;

/* Variables and functions */
long DBtimevaldiff2(struct timeval *, struct timeval *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int mysql_errno(int /*<<< orphan*/ *);
char *mysql_error(int /*<<< orphan*/ *);
scalar_t__ mysql_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *, char *, ...);
long DBbenchmark2(char *msg, char *query, MYSQL *connection) {
  struct timeval startTime;
  struct timeval finishTime;
  gettimeofday(&startTime, 0);
  if (mysql_query(connection, query)) {
    printf("QUERY: %s\n", query);
    printf("ERROR: %s::ErrNum %u: %s\n", msg, mysql_errno(connection),
           mysql_error(connection));
  }
  gettimeofday(&finishTime, 0);
  return DBtimevaldiff2(&startTime, &finishTime);
}


x86 assembly (clang, -O0):
<DBbenchmark2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <mysql_query@plt>
cmp    $0x0,%rax
je     11dd <DBbenchmark2+0x7d>
mov    -0x10(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <mysql_errno@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <mysql_error@plt>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <DBtimevaldiff2@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DBbenchmark2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <mysql_query@plt>
test   %rax,%rax
je     11c8 <DBbenchmark2+0x68>
lea    0xe6a(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <mysql_errno@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <mysql_error@plt>
lea    0xe52(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <DBtimevaldiff2@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [11 x i8] c"QUERY: %s\0A\00"
@.str.1 = [26 x i8] c"ERROR: %s::ErrNum %u: %s\0A\00"
define i64 @DBbenchmark2(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%9 = call i32 @gettimeofday(%struct.timeval* %7, i32 0)
%10 = load i32*, i32** %6
%11 = load i8*, i8** %5
%12 = call i64 @mysql_query(i32* %10, i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %4
%18 = load i32*, i32** %6
%19 = call i32 @mysql_errno(i32* %18)
%20 = load i32*, i32** %6
%21 = call i8* @mysql_error(i32* %20)
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %19, i8* %21)
br label %23
23: ; preds = %14, %3
%24 = call i32 @gettimeofday(%struct.timeval* %8, i32 0)
%25 = call i64 @DBtimevaldiff2(%struct.timeval* %7, %struct.timeval* %8)
ret i64 %25
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [11 x i8] c"QUERY: %s\0A\00"
@.str.1 = [26 x i8] c"ERROR: %s::ErrNum %u: %s\0A\00"
define i64 @DBbenchmark2(i8* %0, i8* %1, i32* %2) {
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %4 to i8*
%7 = bitcast %struct.timeval* %5 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%9 = call i64 @mysql_query(i32* %2, i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %1)
%13 = call i32 @mysql_errno(i32* %2)
%14 = call i8* @mysql_error(i32* %2)
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %13, i8* %14)
br label %16
16: ; preds = %11, %3
%17 = call i32 @gettimeofday(%struct.timeval* %5, i32 0)
%18 = call i64 @DBtimevaldiff2(%struct.timeval* %4, %struct.timeval* %5)
ret i64 %18
}