#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 /*<<< orphan*/ assert(int);
int basex_status(int);
int /*<<< orphan*/ free(char *);
int readstring(int, char **);
int send_db(int, char const *, scalar_t__);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ warnx(char *, ...);
int basex_execute(int sfd, const char *command, char **result, char **info) {
  int rc;
  rc = send_db(sfd, command, strlen(command) + 1);
  if (rc == -1) {
    warnx("Can not send command '%s' to server.", command);
    goto err;
  }
  rc = readstring(sfd, result);
  if (rc == -1) {
    warnx("Can not retrieve result for command '%s' from server.", command);
    goto err;
  }
  rc = readstring(sfd, info);
  if (rc == -1) {
    warnx("Can not retrieve info for command '%s' from server.", *info);
    goto err;
  }
  rc = basex_status(sfd);
  if (rc == -1) {
    warnx("Can not retrieve status.");
    goto err;
  }
  if (rc == 1) {
    warnx("BaseX error message : %s", *info);
    free(*result);
    *result = NULL;
  }
  assert(rc == 0 || rc == 1);
  return rc;
err:
  *result = NULL;
  *info = NULL;
  return -1;
}


x86 assembly (clang, -O0):
<basex_execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <send_db@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11d5 <basex_execute+0x65>
mov    -0x10(%rbp),%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
jmp    12c7 <basex_execute+0x157>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <readstring@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1205 <basex_execute+0x95>
mov    -0x10(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
jmp    12c7 <basex_execute+0x157>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1080 <readstring@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1238 <basex_execute+0xc8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
jmp    12c7 <basex_execute+0x157>
mov    -0x8(%rbp),%edi
call   1090 <basex_status@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1260 <basex_execute+0xf0>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
jmp    12c7 <basex_execute+0x157>
cmpl   $0x1,-0x24(%rbp)
jne    1296 <basex_execute+0x126>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    $0x1,%al
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x35(%rbp)
je     12af <basex_execute+0x13f>
cmpl   $0x1,-0x24(%rbp)
sete   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12e4 <basex_execute+0x174>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basex_execute>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %edi,%ebx
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1070 <send_db@plt>
cmp    $0xffffffff,%eax
je     11de <basex_execute+0x6e>
mov    %ebx,%edi
mov    %r14,%rsi
call   1080 <readstring@plt>
cmp    $0xffffffff,%eax
je     11e7 <basex_execute+0x77>
mov    %ebx,%edi
mov    %r15,%rsi
call   1080 <readstring@plt>
cmp    $0xffffffff,%eax
je     11f3 <basex_execute+0x83>
mov    %ebx,%edi
call   1090 <basex_status@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
je     1224 <basex_execute+0xb4>
cmp    $0xffffffff,%ebp
jne    1244 <basex_execute+0xd4>
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1050 <warnx@plt>
jmp    1204 <basex_execute+0x94>
lea    0xe1b(%rip),%rdi
jmp    11ee <basex_execute+0x7e>
lea    0xe37(%rip),%rdi
mov    %rbp,%rsi
jmp    11fd <basex_execute+0x8d>
mov    (%r15),%rsi
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1050 <warnx@plt>
movq   $0x0,(%r14)
movq   $0x0,(%r15)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%rsi
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1050 <warnx@plt>
mov    (%r14),%rdi
call   1030 <free@plt>
movq   $0x0,(%r14)
xor    %edi,%edi
cmp    $0x2,%ebp
setb   %dil
call   1060 <assert@plt>
jmp    1217 <basex_execute+0xa7>

LLVM IR (-O0):
@.str = [37 x i8] c"Can not send command '%s' to server.\00"
@.str.1 = [54 x i8] c"Can not retrieve result for command '%s' from server.\00"
@.str.2 = [52 x i8] c"Can not retrieve info for command '%s' from server.\00"
@.str.3 = [25 x i8] c"Can not retrieve status.\00"
@.str.4 = [25 x i8] c"BaseX error message : %s\00"
define i32 @basex_execute(i32 %0, i8* %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
%11 = load i32, i32* %6
%12 = load i8*, i8** %7
%13 = load i8*, i8** %7
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = call i32 @send_db(i32 %11, i8* %12, i64 %15)
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %4
%20 = load i8*, i8** %7
%21 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %70
22: ; preds = %4
%23 = load i32, i32* %6
%24 = load i8**, i8*** %8
%25 = call i32 @readstring(i32 %23, i8** %24)
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i8*, i8** %7
%30 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %70
31: ; preds = %22
%32 = load i32, i32* %6
%33 = load i8**, i8*** %9
%34 = call i32 @readstring(i32 %32, i8** %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load i8**, i8*** %9
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %70
41: ; preds = %31
%42 = load i32, i32* %6
%43 = call i32 @basex_status(i32 %42)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %70
48: ; preds = %41
%49 = load i32, i32* %10
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %59
51: ; preds = %48
%52 = load i8**, i8*** %9
%53 = load i8*, i8** %52
%54 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = load i8**, i8*** %8
%56 = load i8*, i8** %55
%57 = call i32 @free(i8* %56)
%58 = load i8**, i8*** %8
store i8* null, i8** %58
br label %59
59: ; preds = %51, %48
%60 = load i32, i32* %10
%61 = icmp eq i32 %60, 0
br i1 %61, label %65, label %62
62: ; preds = %59
%63 = load i32, i32* %10
%64 = icmp eq i32 %63, 1
br label %65
65: ; preds = %62, %59
%66 = phi i1 [ true, %59 ], [ %64, %62 ]
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i32, i32* %10
store i32 %69, i32* %5
br label %73
70: ; preds = %46, %37, %28, %19
%71 = load i8**, i8*** %8
store i8* null, i8** %71
%72 = load i8**, i8*** %9
store i8* null, i8** %72
store i32 -1, i32* %5
br label %73
73: ; preds = %70, %65
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
@.str = [37 x i8] c"Can not send command '%s' to server.\00"
@.str.1 = [54 x i8] c"Can not retrieve result for command '%s' from server.\00"
@.str.2 = [52 x i8] c"Can not retrieve info for command '%s' from server.\00"
@.str.3 = [25 x i8] c"Can not retrieve status.\00"
@.str.4 = [25 x i8] c"BaseX error message : %s\00"
define i32 @basex_execute(i32 %0, i8* %1, i8** %2, i8** %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add nsw i64 %5, 1
%7 = tail call i32 @send_db(i32 %0, i8* %1, i64 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %35
11: ; preds = %4
%12 = tail call i32 @readstring(i32 %0, i8** %2)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %35
16: ; preds = %11
%17 = tail call i32 @readstring(i32 %0, i8** %3)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %35
22: ; preds = %16
%23 = tail call i32 @basex_status(i32 %0)
switch i32 %23, label %31 [
i32 -1, label %24
i32 1, label %26
]
24: ; preds = %22
%25 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %35
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %2
%30 = tail call i32 @free(i8* %29)
store i8* null, i8** %2
br label %31
31: ; preds = %22, %26
%32 = icmp ult i32 %23, 2
%33 = zext i1 %32 to i32
%34 = tail call i32 @assert(i32 %33)
br label %36
35: ; preds = %24, %19, %14, %9
store i8* null, i8** %2
store i8* null, i8** %3
br label %36
36: ; preds = %35, %31
%37 = phi i32 [ -1, %35 ], [ %23, %31 ]
ret i32 %37
}