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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ mysql_close(int /*<<< orphan*/ *);
char *mysql_error(int /*<<< orphan*/ *);
char **mysql_fetch_row(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_free_result(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_init(int /*<<< orphan*/ *);
scalar_t__ mysql_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ mysql_real_connect(int /*<<< orphan*/ *, char *, char *,
                                      char *, char *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *mysql_use_result(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(void) {
  MYSQL *conn;
  MYSQL_RES *res;
  MYSQL_ROW row;
  char *server = "your.server";
  char *user = "your.username";
  char *password = "your.password";
  char *database = "your.database";
  conn = mysql_init(NULL);
  if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    return 1;
  }
  if (mysql_query(conn, "show tables")) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    return 1;
  }
  res = mysql_use_result(conn);
  printf("MySQL Tables in mysql database:\n");
  while ((row = mysql_fetch_row(res)) != NULL) {
    printf("%s \n", row[0]);
  }
  printf("\n");
  if (mysql_query(
          conn,
          "insert into Bruker (brukerNavn, passord) values('test', 'test')")) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    return 1;
  }
  printf("\n");
  if (mysql_query(conn, "select * from Bruker")) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    return 1;
  }
  res = mysql_use_result(conn);
  while ((row = mysql_fetch_row(res)) != NULL) {
    printf("%s %s %s \n", row[0], row[1], row[2]);
  }
  mysql_free_result(res);
  mysql_close(conn);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe4b(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe4e(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe51(%rip),%rax
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <mysql_init@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
xor    %r9d,%r9d
xor    %eax,%eax
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1070 <mysql_real_connect@plt>
cmp    $0x0,%eax
jne    1252 <main+0xb2>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <mysql_error@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xdf5(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1408 <main+0x268>
mov    -0x10(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   1030 <mysql_query@plt>
cmp    $0x0,%rax
je     129f <main+0xff>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <mysql_error@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xda8(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1408 <main+0x268>
mov    -0x10(%rbp),%rdi
call   10b0 <mysql_use_result@plt>
mov    %rax,-0x18(%rbp)
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12eb <main+0x14b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ba <main+0x11a>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xd63(%rip),%rsi
call   1030 <mysql_query@plt>
cmp    $0x0,%rax
je     1346 <main+0x1a6>
mov    0x2cc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <mysql_error@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xd01(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1408 <main+0x268>
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xd48(%rip),%rsi
call   1030 <mysql_query@plt>
cmp    $0x0,%rax
je     13a1 <main+0x201>
mov    0x2c6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <mysql_error@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%rdx
lea    0xca6(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1408 <main+0x268>
mov    -0x10(%rbp),%rdi
call   10b0 <mysql_use_result@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     13ef <main+0x24f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13ae <main+0x20e>
mov    -0x18(%rbp),%rdi
call   10a0 <mysql_free_result@plt>
mov    -0x10(%rbp),%rdi
call   1080 <mysql_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %edi,%edi
call   10b0 <mysql_init@plt>
mov    %rax,%r15
lea    0xe2a(%rip),%rsi
lea    0xe2f(%rip),%rdx
lea    0xe36(%rip),%rcx
lea    0xe3d(%rip),%r8
mov    %rax,%rdi
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1090 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %eax,%eax
je     12a6 <main+0xe6>
lea    0xe2d(%rip),%rsi
mov    %r15,%rdi
call   1050 <mysql_query@plt>
test   %rax,%rax
jne    12a6 <main+0xe6>
mov    %r15,%rdi
call   10d0 <mysql_use_result@plt>
mov    %rax,%rbx
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1060 <mysql_fetch_row@plt>
test   %rax,%rax
je     126a <main+0xaa>
lea    0xe58(%rip),%r14
nopl   0x0(%rax)
mov    (%rax),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <mysql_fetch_row@plt>
test   %rax,%rax
jne    1250 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdcb(%rip),%rsi
mov    %r15,%rdi
call   1050 <mysql_query@plt>
test   %rax,%rax
jne    12a6 <main+0xe6>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xded(%rip),%rsi
mov    %r15,%rdi
call   1050 <mysql_query@plt>
test   %rax,%rax
je     12d3 <main+0x113>
mov    0x2d33(%rip),%rax
mov    (%rax),%ebx
mov    %r15,%rdi
call   10e0 <mysql_error@plt>
lea    0xd78(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   10d0 <mysql_use_result@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <mysql_fetch_row@plt>
test   %rax,%rax
je     1322 <main+0x162>
lea    0xda9(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    0x10(%rax),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <mysql_fetch_row@plt>
test   %rax,%rax
jne    1300 <main+0x140>
mov    %r14,%rdi
call   10c0 <mysql_free_result@plt>
mov    %r15,%rdi
call   10a0 <mysql_close@plt>
xor    %eax,%eax
jmp    12cd <main+0x10d>

LLVM IR (-O0):
@.str = [12 x i8] c"your.server\00"
@.str.1 = [14 x i8] c"your.username\00"
@.str.2 = [14 x i8] c"your.password\00"
@.str.3 = [14 x i8] c"your.database\00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [12 x i8] c"show tables\00"
@.str.6 = [33 x i8] c"MySQL Tables in mysql database:\0A\00"
@.str.7 = [5 x i8] c"%s \0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [64 x i8] c"insert into Bruker (brukerNavn, passord) values('test', 'test')\00"
@.str.10 = [21 x i8] c"select * from Bruker\00"
@.str.11 = [11 x i8] c"%s %s %s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %8
%9 = call i32* @mysql_init(i32* null)
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = load i8*, i8** %7
%14 = load i8*, i8** %8
%15 = call i32 @mysql_real_connect(i32* %10, i8* %11, i8* %12, i8* %13, i8* %14, i32 0, i32* null, i32 0)
%16 = icmp ne i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %0
%18 = load i32, i32* @stderr
%19 = load i32*, i32** %2
%20 = call i8* @mysql_error(i32* %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %20)
store i32 1, i32* %1
br label %87
22: ; preds = %0
%23 = load i32*, i32** %2
%24 = call i64 @mysql_query(i32* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i32*, i32** %2
%29 = call i8* @mysql_error(i32* %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %29)
store i32 1, i32* %1
br label %87
31: ; preds = %22
%32 = load i32*, i32** %2
%33 = call i32* @mysql_use_result(i32* %32)
store i32* %33, i32** %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %39, %31
%36 = load i32*, i32** %3
%37 = call i8** @mysql_fetch_row(i32* %36)
store i8** %37, i8*** %4
%38 = icmp ne i8** %37, null
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i8**, i8*** %4
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %42)
br label %35
44: ; preds = %35
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%46 = load i32*, i32** %2
%47 = call i64 @mysql_query(i32* %46, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0))
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = load i32*, i32** %2
%52 = call i8* @mysql_error(i32* %51)
%53 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %52)
store i32 1, i32* %1
br label %87
54: ; preds = %44
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%56 = load i32*, i32** %2
%57 = call i64 @mysql_query(i32* %56, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %54
%60 = load i32, i32* @stderr
%61 = load i32*, i32** %2
%62 = call i8* @mysql_error(i32* %61)
%63 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %62)
store i32 1, i32* %1
br label %87
64: ; preds = %54
%65 = load i32*, i32** %2
%66 = call i32* @mysql_use_result(i32* %65)
store i32* %66, i32** %3
br label %67
67: ; preds = %71, %64
%68 = load i32*, i32** %3
%69 = call i8** @mysql_fetch_row(i32* %68)
store i8** %69, i8*** %4
%70 = icmp ne i8** %69, null
br i1 %70, label %71, label %82
71: ; preds = %67
%72 = load i8**, i8*** %4
%73 = getelementptr inbounds i8*, i8** %72, i64 0
%74 = load i8*, i8** %73
%75 = load i8**, i8*** %4
%76 = getelementptr inbounds i8*, i8** %75, i64 1
%77 = load i8*, i8** %76
%78 = load i8**, i8*** %4
%79 = getelementptr inbounds i8*, i8** %78, i64 2
%80 = load i8*, i8** %79
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8* %74, i8* %77, i8* %80)
br label %67
82: ; preds = %67
%83 = load i32*, i32** %3
%84 = call i32 @mysql_free_result(i32* %83)
%85 = load i32*, i32** %2
%86 = call i32 @mysql_close(i32* %85)
store i32 0, i32* %1
br label %87
87: ; preds = %82, %59, %49, %26, %17
%88 = load i32, i32* %1
ret i32 %88
}

LLVM IR (-O2):
@.str = [12 x i8] c"your.server\00"
@.str.1 = [14 x i8] c"your.username\00"
@.str.2 = [14 x i8] c"your.password\00"
@.str.3 = [14 x i8] c"your.database\00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [12 x i8] c"show tables\00"
@.str.7 = [5 x i8] c"%s \0A\00"
@.str.9 = [64 x i8] c"insert into Bruker (brukerNavn, passord) values('test', 'test')\00"
@.str.10 = [21 x i8] c"select * from Bruker\00"
@.str.11 = [11 x i8] c"%s %s %s \0A\00"
@str = [32 x i8] c"MySQL Tables in mysql database:\00"
define i32 @main() {
%1 = tail call i32* @mysql_init(i32* null)
%2 = tail call i32 @mysql_real_connect(i32* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 0, i32* null, i32 0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i8* @mysql_error(i32* %1)
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %59
8: ; preds = %0
%9 = tail call i64 @mysql_query(i32* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i8* @mysql_error(i32* %1)
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %13)
br label %59
15: ; preds = %8
%16 = tail call i32* @mysql_use_result(i32* %1)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%18 = tail call i8** @mysql_fetch_row(i32* %16)
%19 = icmp eq i8** %18, null
br i1 %19, label %26, label %20
20: ; preds = %15, %20
%21 = phi i8** [ %24, %20 ], [ %18, %15 ]
%22 = load i8*, i8** %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %22)
%24 = tail call i8** @mysql_fetch_row(i32* %16)
%25 = icmp eq i8** %24, null
br i1 %25, label %26, label %20
26: ; preds = %20, %15
%27 = tail call i32 @putchar(i32 10)
%28 = tail call i64 @mysql_query(i32* %1, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = tail call i8* @mysql_error(i32* %1)
%33 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %32)
br label %59
34: ; preds = %26
%35 = tail call i32 @putchar(i32 10)
%36 = tail call i64 @mysql_query(i32* %1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = tail call i8* @mysql_error(i32* %1)
%41 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %40)
br label %59
42: ; preds = %34
%43 = tail call i32* @mysql_use_result(i32* %1)
%44 = tail call i8** @mysql_fetch_row(i32* %43)
%45 = icmp eq i8** %44, null
br i1 %45, label %56, label %46
46: ; preds = %42, %46
%47 = phi i8** [ %54, %46 ], [ %44, %42 ]
%48 = load i8*, i8** %47
%49 = getelementptr inbounds i8*, i8** %47, i64 1
%50 = load i8*, i8** %49
%51 = getelementptr inbounds i8*, i8** %47, i64 2
%52 = load i8*, i8** %51
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8* %48, i8* %50, i8* %52)
%54 = tail call i8** @mysql_fetch_row(i32* %43)
%55 = icmp eq i8** %54, null
br i1 %55, label %56, label %46
56: ; preds = %46, %42
%57 = tail call i32 @mysql_free_result(i32* %43)
%58 = tail call i32 @mysql_close(i32* %1)
br label %59
59: ; preds = %56, %38, %30, %11, %4
%60 = phi i32 [ 1, %11 ], [ 1, %30 ], [ 1, %38 ], [ 0, %56 ], [ 1, %4 ]
ret i32 %60
}