#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*/ free(char *);
char *receiveMsgFromClient(int);
int /*<<< orphan*/ sendMsgToClient(int, char *);
scalar_t__ strcmp(char *, char *);
int getQuery(int clientFD) {
  int n;
  char *buff = NULL;
  int toRet = -1;
  sendMsgToClient(clientFD,
                  "Enter C to credit, D to debit and exit to terminate");
  while (1) {
    if (buff != NULL)
      free(buff);
    buff = receiveMsgFromClient(clientFD);
    if (strcmp(buff, "exit") == 0) {
      toRet = -1;
      break;
    } else if (strcmp(buff, "C") == 0) {
      toRet = 10;
      break;
    } else if (strcmp(buff, "D") == 0) {
      toRet = 11;
      break;
    } else {
      sendMsgToClient(clientFD, "Unknow Query. Please enter C to credit, D to "
                                "debit and exit to terminate");
    }
  }
  if (buff != NULL)
    free(buff);
  buff = NULL;
  return toRet;
}


x86 assembly (clang, -O0):
<getQuery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe9c(%rip),%rsi
call   1050 <sendMsgToClient@plt>
cmpq   $0x0,-0x10(%rbp)
je     117d <getQuery+0x3d>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
call   1060 <receiveMsgFromClient@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11af <getQuery+0x6f>
movl   $0xffffffff,-0x14(%rbp)
jmp    1219 <getQuery+0xd9>
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d5 <getQuery+0x95>
movl   $0xa,-0x14(%rbp)
jmp    1219 <getQuery+0xd9>
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11fb <getQuery+0xbb>
movl   $0xb,-0x14(%rbp)
jmp    1219 <getQuery+0xd9>
mov    -0x4(%rbp),%edi
lea    0xe38(%rip),%rsi
call   1050 <sendMsgToClient@plt>
jmp    120f <getQuery+0xcf>
jmp    1214 <getQuery+0xd4>
jmp    1169 <getQuery+0x29>
cmpq   $0x0,-0x10(%rbp)
je     122d <getQuery+0xed>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getQuery>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xeac(%rip),%rsi
xor    %ebx,%ebx
lea    0xed7(%rip),%r14
lea    0xed5(%rip),%r15
lea    0xed0(%rip),%r12
lea    0xecb(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1050 <sendMsgToClient@plt>
test   %rbx,%rbx
je     1194 <getQuery+0x54>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1060 <receiveMsgFromClient@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11dd <getQuery+0x9d>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e9 <getQuery+0xa9>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
mov    %r13,%rsi
test   %rax,%rax
jne    1180 <getQuery+0x40>
mov    $0xb,%ebp
test   %rbx,%rbx
jne    11f3 <getQuery+0xb3>
jmp    11fb <getQuery+0xbb>
mov    $0xffffffff,%ebp
test   %rbx,%rbx
jne    11f3 <getQuery+0xb3>
jmp    11fb <getQuery+0xbb>
mov    $0xa,%ebp
test   %rbx,%rbx
je     11fb <getQuery+0xbb>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"Enter C to credit, D to debit and exit to terminate\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [2 x i8] c"C\00"
@.str.3 = [2 x i8] c"D\00"
@.str.4 = [73 x i8] c"Unknow Query. Please enter C to credit, D to debit and exit to terminate\00"
define i32 @getQuery(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
store i8* null, i8** %4
store i32 -1, i32* %5
%6 = load i32, i32* %2
%7 = call i32 @sendMsgToClient(i32 %6, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %1, %36
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = call i32 @free(i8* %12)
br label %14
14: ; preds = %11, %8
%15 = load i32, i32* %2
%16 = call i8* @receiveMsgFromClient(i32 %15)
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 -1, i32* %5
br label %37
21: ; preds = %14
%22 = load i8*, i8** %4
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 10, i32* %5
br label %37
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 11, i32* %5
br label %37
31: ; preds = %26
%32 = load i32, i32* %2
%33 = call i32 @sendMsgToClient(i32 %32, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %31
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
br label %8
37: ; preds = %30, %25, %20
%38 = load i8*, i8** %4
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i8*, i8** %4
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %40, %37
store i8* null, i8** %4
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
@.str = [52 x i8] c"Enter C to credit, D to debit and exit to terminate\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [2 x i8] c"C\00"
@.str.3 = [2 x i8] c"D\00"
@.str.4 = [73 x i8] c"Unknow Query. Please enter C to credit, D to debit and exit to terminate\00"
define i32 @getQuery(i32 %0) {
br label %2
2: ; preds = %16, %1
%3 = phi i8* [ getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([73 x i8], [73 x i8]* @.str.4, i64 0, i64 0), %16 ]
%4 = phi i8* [ null, %1 ], [ %10, %16 ]
%5 = tail call i32 @sendMsgToClient(i32 %0, i8* %3)
%6 = icmp eq i8* %4, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @free(i8* %4)
br label %9
9: ; preds = %7, %2
%10 = tail call i8* @receiveMsgFromClient(i32 %0)
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %9
%14 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %2
19: ; preds = %16, %13, %9
%20 = phi i32 [ -1, %9 ], [ 10, %13 ], [ 11, %16 ]
%21 = icmp eq i8* %10, null
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @free(i8* %10)
br label %24
24: ; preds = %22, %19
ret i32 %20
}