#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 *);
scalar_t__ isANumber(char *);
char *receiveMsgFromClient(int);
int /*<<< orphan*/ sendMsgToClient(int, char *);
scalar_t__ strcmp(char *, char *);
double strtod(char *, int /*<<< orphan*/ *);
double getAmount(int clientFD) {
  int n;
  double toRet = -1;
  char *buff = NULL;
  sendMsgToClient(clientFD, "Enter Numerical Amount and exit to terminate");
  while (1) {
    if (buff != NULL)
      free(buff);
    buff = receiveMsgFromClient(clientFD);
    if (strcmp(buff, "exit") == 0) {
      toRet = -1.0;
      break;
    } else if (isANumber(buff)) {
      toRet = strtod(buff, NULL);
      if (toRet < 0.0f)
        sendMsgToClient(
            clientFD,
            "Negative Amount Not Allowed. Please enter a positive amount");
      break;
    } else {
      sendMsgToClient(
          clientFD,
          "Invalid amount. Please enter a valid amount and exit to terminate");
    }
  }
  if (buff != NULL)
    free(buff);
  buff = NULL;
  return toRet;
}


x86 assembly (clang, -O0):
<getAmount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  0xe8d(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe7e(%rip),%rsi
call   1070 <sendMsgToClient@plt>
cmpq   $0x0,-0x18(%rbp)
je     11a3 <getAmount+0x43>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
call   1080 <receiveMsgFromClient@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11db <getAmount+0x7b>
movsd  0xe2f(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    123b <getAmount+0xdb>
mov    -0x18(%rbp),%rdi
call   1040 <isANumber@plt>
cmp    $0x0,%rax
je     1222 <getAmount+0xc2>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <strtod@plt>
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    121d <getAmount+0xbd>
mov    -0x4(%rbp),%edi
lea    0xe22(%rip),%rsi
call   1070 <sendMsgToClient@plt>
jmp    123b <getAmount+0xdb>
mov    -0x4(%rbp),%edi
lea    0xe4a(%rip),%rsi
call   1070 <sendMsgToClient@plt>
jmp    1236 <getAmount+0xd6>
jmp    118f <getAmount+0x2f>
cmpq   $0x0,-0x18(%rbp)
je     124f <getAmount+0xef>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAmount>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xe98(%rip),%rsi
xor    %ebx,%ebx
lea    0xebc(%rip),%r14
movsd  0xe7f(%rip),%xmm0
movsd  %xmm0,(%rsp)
lea    0xee9(%rip),%r15
nopl   (%rax)
mov    %ebp,%edi
call   1070 <sendMsgToClient@plt>
test   %rbx,%rbx
je     11a4 <getAmount+0x44>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1080 <receiveMsgFromClient@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f5 <getAmount+0x95>
mov    %rbx,%rdi
call   1040 <isANumber@plt>
mov    %r15,%rsi
test   %rax,%rax
je     1190 <getAmount+0x30>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <strtod@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,(%rsp)
ucomisd %xmm0,%xmm1
jbe    11f5 <getAmount+0x95>
lea    0xe4c(%rip),%rsi
mov    %ebp,%edi
call   1070 <sendMsgToClient@plt>
test   %rbx,%rbx
je     1202 <getAmount+0xa2>
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Enter Numerical Amount and exit to terminate\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [60 x i8] c"Negative Amount Not Allowed. Please enter a positive amount\00"
@.str.3 = [66 x i8] c"Invalid amount. Please enter a valid amount and exit to terminate\00"
define double @getAmount(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca i8*
store i32 %0, i32* %2
store double -1.000000e+00, double* %4
store i8* null, i8** %5
%6 = load i32, i32* %2
%7 = call i32 @sendMsgToClient(i32 %6, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %1, %38
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i8*, i8** %5
%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** %5
%17 = load i8*, i8** %5
%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 double -1.000000e+00, double* %4
br label %39
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = call i64 @isANumber(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = call double @strtod(i8* %26, i32* null)
store double %27, double* %4
%28 = load double, double* %4
%29 = fcmp olt double %28, 0.000000e+00
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* %2
%32 = call i32 @sendMsgToClient(i32 %31, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %30, %25
br label %39
34: ; preds = %21
%35 = load i32, i32* %2
%36 = call i32 @sendMsgToClient(i32 %35, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %34
br label %38
38: ; preds = %37
br label %8
39: ; preds = %33, %20
%40 = load i8*, i8** %5
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8*, i8** %5
%44 = call i32 @free(i8* %43)
br label %45
45: ; preds = %42, %39
store i8* null, i8** %5
%46 = load double, double* %4
ret double %46
}

LLVM IR (-O2):
@.str = [45 x i8] c"Enter Numerical Amount and exit to terminate\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [60 x i8] c"Negative Amount Not Allowed. Please enter a positive amount\00"
@.str.3 = [66 x i8] c"Invalid amount. Please enter a valid amount and exit to terminate\00"
define double @getAmount(i32 %0) {
br label %2
2: ; preds = %13, %1
%3 = phi i8* [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), %13 ]
%4 = phi i8* [ null, %1 ], [ %10, %13 ]
%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 %21, label %13
13: ; preds = %9
%14 = tail call i64 @isANumber(i8* %10)
%15 = icmp eq i64 %14, 0
br i1 %15, label %2, label %16
16: ; preds = %13
%17 = tail call double @strtod(i8* nocapture %10, i32* null)
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @sendMsgToClient(i32 %0, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %9, %16, %19
%22 = phi double [ %17, %19 ], [ %17, %16 ], [ -1.000000e+00, %9 ]
%23 = icmp eq i8* %10, null
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @free(i8* %10)
br label %26
26: ; preds = %24, %21
ret double %22
}