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

/* Variables and functions */
int basex_authenticate(int, char *, char *);
int /*<<< orphan*/ basex_close(int);
int basex_connect(char *, char *);
int basex_execute(int, char const *, char **, char **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ warnx(char *, ...);
int main(void) {
  int sfd, rc;
  sfd = basex_connect("localhost", "1984");
  if (sfd == -1) {
    warnx("Can not connect to BaseX server.");
    return 0;
  }
  rc = basex_authenticate(sfd, "admin", "admin");
  if (rc == -1) {
    warnx("Access to DB denied.");
    goto out;
  }
  const char *command = "xquery 1 + 1";
  char *result;
  char *info;
  rc = basex_execute(sfd, command, &result, &info);
  if (rc == -1) {
    warnx("An error occured during execution of '%s'.", command);
    goto free_and_out;
  }
  if (rc == 1) {
    warnx("Processing of '%s' failed.", command);
  }
  printf("command: '%s'\n", command);
  printf("result : '%s'\n", result);
  printf("%s : '%s'\n", (rc == 1) ? "error" : "info", info);
free_and_out:
  free(result);
  free(info);
out:
  basex_close(sfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1030 <basex_connect@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b9 <main+0x49>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b9 <main+0x149>
mov    -0x8(%rbp),%edi
lea    0xe6d(%rip),%rdx
mov    %rdx,%rsi
call   1080 <basex_authenticate@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11eb <main+0x7b>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
jmp    12aa <main+0x13a>
lea    0xe59(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1090 <basex_execute@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    122e <main+0xbe>
mov    -0x18(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
jmp    1298 <main+0x128>
cmpl   $0x1,-0xc(%rbp)
jne    124a <main+0xda>
mov    -0x18(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
mov    -0x18(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%ecx
lea    0xe55(%rip),%rsi
lea    0xe48(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rsi
mov    -0x28(%rbp),%rdx
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x8(%rbp),%edi
call   1050 <basex_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe82(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1030 <basex_connect@plt>
cmp    $0xffffffff,%eax
je     11e3 <main+0x73>
mov    %eax,%ebx
lea    0xe98(%rip),%rdx
mov    %eax,%edi
mov    %rdx,%rsi
call   1080 <basex_authenticate@plt>
cmp    $0xffffffff,%eax
je     11f6 <main+0x86>
lea    0xe9d(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
call   1090 <basex_execute@plt>
cmp    $0x1,%eax
je     1206 <main+0x96>
cmp    $0xffffffff,%eax
jne    1224 <main+0xb4>
lea    0xe88(%rip),%rdi
lea    0xe74(%rip),%rsi
xor    %eax,%eax
call   1070 <warnx@plt>
jmp    1269 <main+0xf9>
lea    0xe25(%rip),%rdi
xor    %eax,%eax
call   1070 <warnx@plt>
jmp    1284 <main+0x114>
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1070 <warnx@plt>
jmp    127d <main+0x10d>
lea    0xe76(%rip),%rdi
lea    0xe37(%rip),%rsi
xor    %eax,%eax
call   1070 <warnx@plt>
lea    0xea5(%rip),%r14
jmp    122b <main+0xbb>
lea    0xea2(%rip),%r14
lea    0xe6c(%rip),%rdi
lea    0xe12(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%rsi
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rdx
lea    0xe5d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%rdi
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    %ebx,%edi
call   1050 <basex_close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"1984\00"
@.str.2 = [33 x i8] c"Can not connect to BaseX server.\00"
@.str.3 = [6 x i8] c"admin\00"
@.str.4 = [21 x i8] c"Access to DB denied.\00"
@.str.5 = [13 x i8] c"xquery 1 + 1\00"
@.str.6 = [43 x i8] c"An error occured during execution of '%s'.\00"
@.str.7 = [27 x i8] c"Processing of '%s' failed.\00"
@.str.8 = [15 x i8] c"command: '%s'\0A\00"
@.str.9 = [15 x i8] c"result : '%s'\0A\00"
@.str.10 = [11 x i8] c"%s : '%s'\0A\00"
@.str.11 = [6 x i8] c"error\00"
@.str.12 = [5 x i8] c"info\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i32 @basex_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %53
12: ; preds = %0
%13 = load i32, i32* %2
%14 = call i32 @basex_authenticate(i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %50
19: ; preds = %12
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8** %4
%20 = load i32, i32* %2
%21 = load i8*, i8** %4
%22 = call i32 @basex_execute(i32 %20, i8* %21, i8** %5, i8** %6)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i8* %26)
br label %45
28: ; preds = %19
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %4
%33 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %28
%35 = load i8*, i8** %4
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %5
%38 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, 1
%41 = zext i1 %40 to i64
%42 = select i1 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0)
%43 = load i8*, i8** %6
%44 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i8* %42, i8* %43)
br label %45
45: ; preds = %34, %25
%46 = load i8*, i8** %5
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %6
%49 = call i32 @free(i8* %48)
br label %50
50: ; preds = %45, %17
%51 = load i32, i32* %2
%52 = call i32 @basex_close(i32 %51)
store i32 0, i32* %1
br label %53
53: ; preds = %50, %10
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"1984\00"
@.str.2 = [33 x i8] c"Can not connect to BaseX server.\00"
@.str.3 = [6 x i8] c"admin\00"
@.str.4 = [21 x i8] c"Access to DB denied.\00"
@.str.5 = [13 x i8] c"xquery 1 + 1\00"
@.str.6 = [43 x i8] c"An error occured during execution of '%s'.\00"
@.str.7 = [27 x i8] c"Processing of '%s' failed.\00"
@.str.8 = [15 x i8] c"command: '%s'\0A\00"
@.str.9 = [15 x i8] c"result : '%s'\0A\00"
@.str.10 = [11 x i8] c"%s : '%s'\0A\00"
@.str.11 = [6 x i8] c"error\00"
@.str.12 = [5 x i8] c"info\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = tail call i32 @basex_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %32
7: ; preds = %0
%8 = tail call i32 @basex_authenticate(i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %30
12: ; preds = %7
%13 = call i32 @basex_execute(i32 %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8** %1, i8** %2)
switch i32 %13, label %18 [
i32 -1, label %14
i32 1, label %16
]
14: ; preds = %12
%15 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %25
16: ; preds = %12
%17 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %18
18: ; preds = %12, %16
%19 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), %16 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), %12 ]
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%21 = load i8*, i8** %1
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %2
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i8* %19, i8* %23)
br label %25
25: ; preds = %18, %14
%26 = load i8*, i8** %1
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %2
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %25, %10
%31 = call i32 @basex_close(i32 %3)
br label %32
32: ; preds = %30, %5
ret i32 0
}