#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 */
scalar_t__ checkIfUserExists(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
char *receiveMsgFromClient(int);
int /*<<< orphan*/ sendMsgToClient(int, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int getUserName(int clientFD, char **userName) {
  int n;
  char *buff = NULL;
  int toRet = -1;
  sendMsgToClient(clientFD, "Enter Username of the account to Credit or Debit "
                            "into and exit to terminate");
  while (1) {
    if (buff != NULL)
      free(buff);
    buff = receiveMsgFromClient(clientFD);
    if (strcmp(buff, "exit") == 0) {
      toRet = -1;
      break;
    } else if (checkIfUserExists(buff)) {
      *userName = (char *)malloc((n + 1) * sizeof(char));
      strcpy(*userName, buff);
      toRet = 1;
      break;
    } else {
      sendMsgToClient(clientFD, "Unknow user. Please enter a valid username.");
    }
  }
  if (buff != NULL)
    free(buff);
  buff = NULL;
  return toRet;
}


x86 assembly (clang, -O0):
<getUserName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe68(%rip),%rsi
call   1080 <sendMsgToClient@plt>
cmpq   $0x0,-0x20(%rbp)
je     11b1 <getUserName+0x41>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
call   1090 <receiveMsgFromClient@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e3 <getUserName+0x73>
movl   $0xffffffff,-0x24(%rbp)
jmp    1248 <getUserName+0xd8>
mov    -0x20(%rbp),%rdi
call   1050 <checkIfUserExists@plt>
cmp    $0x0,%rax
je     122f <getUserName+0xbf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x24(%rbp)
jmp    1248 <getUserName+0xd8>
mov    -0x4(%rbp),%edi
lea    0xe18(%rip),%rsi
call   1080 <sendMsgToClient@plt>
jmp    1243 <getUserName+0xd3>
jmp    119d <getUserName+0x2d>
cmpq   $0x0,-0x20(%rbp)
je     125c <getUserName+0xec>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getUserName>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe7c(%rip),%rsi
xor    %ebx,%ebx
lea    0xebf(%rip),%r15
lea    0xebd(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
call   1080 <sendMsgToClient@plt>
test   %rbx,%rbx
je     11b4 <getUserName+0x44>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1090 <receiveMsgFromClient@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ff <getUserName+0x8f>
mov    %rbx,%rdi
call   1050 <checkIfUserExists@plt>
mov    %r12,%rsi
test   %rax,%rax
je     11a0 <getUserName+0x30>
xor    %edi,%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
jne    1209 <getUserName+0x99>
jmp    1211 <getUserName+0xa1>
mov    $0xffffffff,%ebp
test   %rbx,%rbx
je     1211 <getUserName+0xa1>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [76 x i8] c"Enter Username of the account to Credit or Debit into and exit to terminate\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [44 x i8] c"Unknow user. Please enter a valid username.\00"
define i32 @getUserName(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* null, i8** %6
store i32 -1, i32* %7
%8 = load i32, i32* %3
%9 = call i32 @sendMsgToClient(i32 %8, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %2, %44
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i8*, i8** %6
%15 = call i32 @free(i8* %14)
br label %16
16: ; preds = %13, %10
%17 = load i32, i32* %3
%18 = call i8* @receiveMsgFromClient(i32 %17)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 -1, i32* %7
br label %45
23: ; preds = %16
%24 = load i8*, i8** %6
%25 = call i64 @checkIfUserExists(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %23
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 1
%32 = trunc i64 %31 to i32
%33 = call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to i8*
%35 = load i8**, i8*** %4
store i8* %34, i8** %35
%36 = load i8**, i8*** %4
%37 = load i8*, i8** %36
%38 = load i8*, i8** %6
%39 = call i32 @strcpy(i8* %37, i8* %38)
store i32 1, i32* %7
br label %45
40: ; preds = %23
%41 = load i32, i32* %3
%42 = call i32 @sendMsgToClient(i32 %41, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %40
br label %44
44: ; preds = %43
br label %10
45: ; preds = %27, %22
%46 = load i8*, i8** %6
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i8*, i8** %6
%50 = call i32 @free(i8* %49)
br label %51
51: ; preds = %48, %45
store i8* null, i8** %6
%52 = load i32, i32* %7
ret i32 %52
}

LLVM IR (-O2):
@.str = [76 x i8] c"Enter Username of the account to Credit or Debit into and exit to terminate\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [44 x i8] c"Unknow user. Please enter a valid username.\00"
define i32 @getUserName(i32 %0, i8** nocapture writeonly %1) {
br label %3
3: ; preds = %14, %2
%4 = phi i8* [ getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), %14 ]
%5 = phi i8* [ null, %2 ], [ %11, %14 ]
%6 = tail call i32 @sendMsgToClient(i32 %0, i8* %4)
%7 = icmp eq i8* %5, null
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @free(i8* %5)
br label %10
10: ; preds = %8, %3
%11 = tail call i8* @receiveMsgFromClient(i32 %0)
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = tail call i64 @checkIfUserExists(i8* %11)
%16 = icmp eq i64 %15, 0
br i1 %16, label %3, label %17
17: ; preds = %14
%18 = tail call i64 @malloc(i32 0)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %1
%20 = tail call i32 @strcpy(i8* %19, i8* %11)
br label %21
21: ; preds = %10, %17
%22 = phi i32 [ 1, %17 ], [ -1, %10 ]
%23 = icmp eq i8* %11, null
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @free(i8* %11)
br label %26
26: ; preds = %24, %21
ret i32 %22
}