#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ addStrings(char **, char *, char);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
char *readFromFile(int /*<<< orphan*/ *);
char *returnBalance(char *);
int /*<<< orphan*/ sendMsgToClient(int, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
char *strtok_r(char *, char *, char **);
void printBalanceOfAllUsers(int clientFD) {
  FILE *fp = fopen("login_file", "r");
  char delim[] = ", \n";
  char *str = readFromFile(fp);
  fclose(fp);
  char *miniSt =
      (char *)malloc((strlen("User  Avail. Balance") + 1) * sizeof(char));
  strcpy(miniSt, "User  Avail. Balance");
  miniSt[strlen("User  Avail. Balance")] = 0;
  char *save_ptr;
  char *tok = strtok_r(str, delim, &save_ptr);
  do {
    char *probableFileName = (char *)malloc(((strlen(tok) + 1)) * sizeof(char));
    strcpy(probableFileName, tok);
    probableFileName[strlen(tok)] = 0;
    tok = strtok_r(NULL, delim, &save_ptr);
    tok = strtok_r(NULL, delim, &save_ptr);
    if (strcmp(tok, "U") == 0) {
      char *bal = returnBalance(probableFileName);
      addStrings(&miniSt, probableFileName, '\n');
      addStrings(&miniSt, bal, ' ');
      free(bal);
      bal = NULL;
    }
    free(probableFileName);
    probableFileName = NULL;
    tok = NULL;
  } while ((tok = strtok_r(NULL, delim, &save_ptr)) != NULL);
  if (str != NULL)
    free(str);
  if (miniSt != NULL)
    sendMsgToClient(clientFD, miniSt);
  else
    sendMsgToClient(clientFD, "No User in bank");
  if (miniSt != NULL)
    free(miniSt);
  miniSt = NULL;
}


x86 assembly (clang, -O0):
<printBalanceOfAllUsers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe2e(%rip),%rdi
lea    0xe32(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    0xe25(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <readFromFile@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xe09(%rip),%rdi
call   1060 <strlen@plt>
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xdd2(%rip),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x30(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x30(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xd48(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    132f <printBalanceOfAllUsers+0x16f>
mov    -0x40(%rbp),%rdi
call   10a0 <returnBalance@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rsi
lea    -0x28(%rbp),%rdi
mov    $0xa,%edx
call   10d0 <addStrings@plt>
mov    -0x48(%rbp),%rsi
lea    -0x28(%rbp),%rdi
mov    $0x20,%edx
call   10d0 <addStrings@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x30(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1264 <printBalanceOfAllUsers+0xa4>
cmpq   $0x0,-0x20(%rbp)
je     137b <printBalanceOfAllUsers+0x1bb>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
je     1397 <printBalanceOfAllUsers+0x1d7>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   10c0 <sendMsgToClient@plt>
jmp    13a6 <printBalanceOfAllUsers+0x1e6>
mov    -0x4(%rbp),%edi
lea    0xc87(%rip),%rsi
call   10c0 <sendMsgToClient@plt>
cmpq   $0x0,-0x28(%rbp)
je     13ba <printBalanceOfAllUsers+0x1fa>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBalanceOfAllUsers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,0x4(%rsp)
lea    0xe27(%rip),%rdi
lea    0xe2b(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%rbx
movl   $0xa202c,0x14(%rsp)
mov    %rax,%rdi
call   1080 <readFromFile@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x15,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
lea    0xdf1(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
movb   $0x0,0x14(%rbx)
lea    0x14(%rsp),%r13
lea    0x20(%rsp),%r12
mov    %rbp,0x18(%rsp)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1070 <strtok_r@plt>
mov    %rax,%r15
lea    0xdd3(%rip),%rbx
jmp    1281 <printBalanceOfAllUsers+0xc1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1070 <strtok_r@plt>
mov    %rax,%r15
test   %rax,%rax
je     1319 <printBalanceOfAllUsers+0x159>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
xor    %edi,%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1070 <strtok_r@plt>
xor    %edi,%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1070 <strtok_r@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1260 <printBalanceOfAllUsers+0xa0>
mov    %r14,%rdi
call   10a0 <returnBalance@plt>
mov    %rax,%rbp
mov    %rbx,%r15
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   10d0 <addStrings@plt>
mov    %rbx,%rdi
mov    %r15,%rbx
mov    %rbp,%rsi
mov    $0x20,%edx
call   10d0 <addStrings@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    1260 <printBalanceOfAllUsers+0xa0>
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     1328 <printBalanceOfAllUsers+0x168>
call   1030 <free@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
jne    1339 <printBalanceOfAllUsers+0x179>
lea    0xceb(%rip),%rsi
mov    0x4(%rsp),%edi
call   10c0 <sendMsgToClient@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1351 <printBalanceOfAllUsers+0x191>
call   1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"login_file\00"
@.str.1 = [2 x i8] c"r\00"
@__const.printBalanceOfAllUsers.delim = [4 x i8] c", \0A\00"
@.str.2 = [21 x i8] c"User Avail. Balance\00"
@.str.3 = [2 x i8] c"U\00"
@.str.4 = [16 x i8] c"No User in bank\00"
define void @printBalanceOfAllUsers(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [4 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 %0, i32* %2
%11 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = bitcast [4 x i8]* %4 to i8*
%13 = load i32*, i32** %3
%14 = call i8* @readFromFile(i32* %13)
store i8* %14, i8** %5
%15 = load i32*, i32** %3
%16 = call i32 @fclose(i32* %15)
%17 = call i64 @strlen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%18 = add i64 %17, 1
%19 = mul i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%25 = load i8*, i8** %6
%26 = call i64 @strlen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 0, i8* %27
%28 = load i8*, i8** %5
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%30 = call i8* @strtok_r(i8* %28, i8* %29, i8** %7)
store i8* %30, i8** %8
br label %31
31: ; preds = %65, %1
%32 = load i8*, i8** %8
%33 = call i64 @strlen(i8* %32)
%34 = add i64 %33, 1
%35 = mul i64 %34, 1
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %9
%39 = load i8*, i8** %9
%40 = load i8*, i8** %8
%41 = call i32 @strcpy(i8* %39, i8* %40)
%42 = load i8*, i8** %9
%43 = load i8*, i8** %8
%44 = call i64 @strlen(i8* %43)
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%47 = call i8* @strtok_r(i8* null, i8* %46, i8** %7)
store i8* %47, i8** %8
%48 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%49 = call i8* @strtok_r(i8* null, i8* %48, i8** %7)
store i8* %49, i8** %8
%50 = load i8*, i8** %8
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %62
53: ; preds = %31
%54 = load i8*, i8** %9
%55 = call i8* @returnBalance(i8* %54)
store i8* %55, i8** %10
%56 = load i8*, i8** %9
%57 = call i32 @addStrings(i8** %6, i8* %56, i8 signext 10)
%58 = load i8*, i8** %10
%59 = call i32 @addStrings(i8** %6, i8* %58, i8 signext 32)
%60 = load i8*, i8** %10
%61 = call i32 @free(i8* %60)
store i8* null, i8** %10
br label %62
62: ; preds = %53, %31
%63 = load i8*, i8** %9
%64 = call i32 @free(i8* %63)
store i8* null, i8** %9
store i8* null, i8** %8
br label %65
65: ; preds = %62
%66 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%67 = call i8* @strtok_r(i8* null, i8* %66, i8** %7)
store i8* %67, i8** %8
%68 = icmp ne i8* %67, null
br i1 %68, label %31, label %69
69: ; preds = %65
%70 = load i8*, i8** %5
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %75
72: ; preds = %69
%73 = load i8*, i8** %5
%74 = call i32 @free(i8* %73)
br label %75
75: ; preds = %72, %69
%76 = load i8*, i8** %6
%77 = icmp ne i8* %76, null
br i1 %77, label %78, label %82
78: ; preds = %75
%79 = load i32, i32* %2
%80 = load i8*, i8** %6
%81 = call i32 @sendMsgToClient(i32 %79, i8* %80)
br label %85
82: ; preds = %75
%83 = load i32, i32* %2
%84 = call i32 @sendMsgToClient(i32 %83, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %85
85: ; preds = %82, %78
%86 = load i8*, i8** %6
%87 = icmp ne i8* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i8*, i8** %6
%90 = call i32 @free(i8* %89)
br label %91
91: ; preds = %88, %85
store i8* null, i8** %6
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"login_file\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"User Avail. Balance\00"
@.str.3 = [2 x i8] c"U\00"
@.str.4 = [16 x i8] c"No User in bank\00"
define void @printBalanceOfAllUsers(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = bitcast i32* %2 to i8*
store i32 663596, i32* %2
%7 = tail call i8* @readFromFile(i32* %5)
%8 = tail call i32 @fclose(i32* %5)
%9 = bitcast i8** %3 to i8*
%10 = tail call i64 @malloc(i32 21)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
%12 = tail call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds i8, i8* %11, i64 20
store i8 0, i8* %13
%14 = bitcast i8** %4 to i8*
%15 = call i8* @strtok_r(i8* %7, i8* %6, i8** %4)
br label %16
16: ; preds = %35, %1
%17 = phi i8* [ %15, %1 ], [ %37, %35 ]
%18 = call i64 @strlen(i8* dereferenceable(1) %17)
%19 = trunc i64 %18 to i32
%20 = add i32 %19, 1
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @strcpy(i8* %22, i8* %17)
%24 = call i64 @strlen(i8* dereferenceable(1) %17)
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 0, i8* %25
%26 = call i8* @strtok_r(i8* null, i8* %6, i8** %4)
%27 = call i8* @strtok_r(i8* null, i8* %6, 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 %35
30: ; preds = %16
%31 = call i8* @returnBalance(i8* %22)
%32 = call i32 @addStrings(i8** %3, i8* %22, i8 signext 10)
%33 = call i32 @addStrings(i8** %3, i8* %31, i8 signext 32)
%34 = call i32 @free(i8* %31)
br label %35
35: ; preds = %30, %16
%36 = call i32 @free(i8* %22)
%37 = call i8* @strtok_r(i8* null, i8* %6, i8** %4)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %16
39: ; preds = %35
%40 = icmp eq i8* %7, null
br i1 %40, label %43, label %41
41: ; preds = %39
%42 = call i32 @free(i8* %7)
br label %43
43: ; preds = %41, %39
%44 = load i8*, i8** %3
%45 = icmp eq i8* %44, null
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = call i32 @sendMsgToClient(i32 %0, i8* %44)
br label %50
48: ; preds = %43
%49 = call i32 @sendMsgToClient(i32 %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
%51 = load i8*, i8** %3
%52 = icmp eq i8* %51, null
br i1 %52, label %55, label %53
53: ; preds = %50
%54 = call i32 @free(i8* %51)
br label %55
55: ; preds = %53, %50
ret void
}