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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ conn_db(char *, char const *, char const *, char *);
int /*<<< orphan*/ disconn_db();
int /*<<< orphan*/ init_db();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ sqldb(char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
void work(const char *userid, const char *password) {
  init_db();
  if (conn_db("localhost", userid, password, "test") != 0) {
    return;
  }
  char buf[2048];
  while (1) {
    write(STDOUT_FILENO, "mysql1>", strlen("mysql1>"));
    memset(buf, 0, sizeof(buf));
    read(STDIN_FILENO, buf, sizeof(buf));
    if (strncmp(buf, "quit", 4) == 0)
      break;
    sqldb(buf);
  }
  disconn_db();
}


x86 assembly (clang, -O0):
<work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <init_db@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe47(%rip),%rdi
lea    0xe4a(%rip),%rcx
call   1080 <conn_db@plt>
cmp    $0x0,%rax
je     11d4 <work+0x44>
jmp    1274 <work+0xe4>
jmp    11d9 <work+0x49>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x814(%rbp)
lea    0xe20(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x814(%rbp),%edi
mov    %eax,%edx
lea    0xe0c(%rip),%rsi
call   1040 <write@plt>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rsi
mov    $0x800,%edx
call   1070 <read@plt>
lea    -0x810(%rbp),%rdi
lea    0xdd4(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    125c <work+0xcc>
jmp    126d <work+0xdd>
lea    -0x810(%rbp),%rdi
call   1090 <sqldb@plt>
jmp    11d9 <work+0x49>
mov    $0x0,%al
call   10b0 <disconn_db@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   10a0 <init_db@plt>
lea    0xe4b(%rip),%rdi
lea    0xe4e(%rip),%rcx
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <conn_db@plt>
test   %rax,%rax
jne    124e <work+0xbe>
mov    0x2e19(%rip),%r12
lea    0xe31(%rip),%r14
mov    %rsp,%rbx
mov    0x2df0(%rip),%r13
lea    0xe28(%rip),%r15
nop
mov    (%r12),%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1070 <read@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1247 <work+0xb7>
mov    %rbx,%rdi
call   1090 <sqldb@plt>
jmp    11f0 <work+0x60>
xor    %eax,%eax
call   10b0 <disconn_db@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"test\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [8 x i8] c"mysql1>\00"
@STDIN_FILENO = global i32 0
@.str.3 = [5 x i8] c"quit\00"
define void @work(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [2048 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i32 (...) @init_db()
%7 = load i8*, i8** %3
%8 = load i8*, i8** %4
%9 = call i64 @conn_db(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
br label %31
12: ; preds = %2
br label %13
13: ; preds = %12, %26
%14 = load i32, i32* @STDOUT_FILENO
%15 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @write(i32 %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 2048)
%19 = load i32, i32* @STDIN_FILENO
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 2048)
%22 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %13
br label %29
26: ; preds = %13
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%28 = call i32 @sqldb(i8* %27)
br label %13
29: ; preds = %25
%30 = call i32 (...) @disconn_db()
br label %31
31: ; preds = %29, %11
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"test\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [8 x i8] c"mysql1>\00"
@STDIN_FILENO = global i32 0
@.str.3 = [5 x i8] c"quit\00"
define void @work(i8* %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = tail call i32 (...) @init_db()
%5 = tail call i64 @conn_db(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %2
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
br label %9
9: ; preds = %18, %7
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @write(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 @memset(i8* %8, i32 0, i32 2048)
%14 = load i32, i32* @STDIN_FILENO
%15 = call i32 @read(i32 %14, i8* %8, i32 2048)
%16 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %9
%19 = call i32 @sqldb(i8* %8)
br label %9
20: ; preds = %9
%21 = call i32 (...) @disconn_db()
br label %22
22: ; preds = %2, %20
ret void
}