#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*/ Bank_GetAcctByName(char *, int);
char *Bank_GetAcctName(int);
int Bank_GetBalance(int);
scalar_t__ Bank_Transfer(int /*<<< orphan*/, int, int, char const *);
int /*<<< orphan*/ Log_Info(char *, char *, int, char *, int, int,
                            char const *);
int /*<<< orphan*/ free(char *);
int DispenseSet(int ActualUser, int User, int Balance, const char *ReasonGiven,
                int *OrigBalance) {
  int curBal = Bank_GetBalance(User);
  char *byName, *dstName;
  if (Bank_Transfer(Bank_GetAcctByName(">countersum", 1), User,
                    Balance - curBal, ReasonGiven))
    return -1;
  byName = Bank_GetAcctName(ActualUser);
  dstName = Bank_GetAcctName(User);
  Log_Info("set balance of %s to %i by %s [was %i, balance %i] - %s", dstName,
           Balance, byName, curBal, Bank_GetBalance(User), ReasonGiven);
  *OrigBalance = curBal;
  free(byName);
  free(dstName);
  return 0;
}


x86 assembly (clang, -O0):
<DispenseSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <Bank_GetBalance@plt>
mov    %eax,-0x24(%rbp)
lea    0xe75(%rip),%rdi
mov    $0x1,%esi
call   1080 <Bank_GetAcctByName@plt>
mov    %eax,%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
sub    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <Bank_Transfer@plt>
cmp    $0x0,%rax
je     11bf <DispenseSet+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <DispenseSet+0xe3>
mov    -0x8(%rbp),%edi
call   1050 <Bank_GetAcctName@plt>
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <Bank_GetAcctName@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <Bank_GetBalance@plt>
mov    -0x58(%rbp),%rsi
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    -0x3c(%rbp),%r8d
mov    %eax,%r9d
mov    -0x18(%rbp),%rax
lea    0xdf4(%rip),%rdi
mov    %rax,(%rsp)
call   1070 <Log_Info@plt>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DispenseSet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%r12
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r13d
mov    %esi,%edi
call   1060 <Bank_GetBalance@plt>
mov    %eax,%ebx
lea    0xe74(%rip),%rdi
mov    $0x1,%esi
call   1080 <Bank_GetAcctByName@plt>
mov    %r15d,%edx
sub    %ebx,%edx
mov    %eax,%edi
mov    %ebp,%esi
mov    %r12,%rcx
call   1040 <Bank_Transfer@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    120d <DispenseSet+0xad>
mov    %r13d,%edi
call   1050 <Bank_GetAcctName@plt>
mov    %rax,%r13
mov    %ebp,%edi
call   1050 <Bank_GetAcctName@plt>
mov    %r14,0x10(%rsp)
mov    %rax,%r14
mov    %ebp,%edi
call   1060 <Bank_GetBalance@plt>
mov    %r12,(%rsp)
lea    0xe2c(%rip),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %r13,%rcx
mov    %ebx,%r8d
mov    %eax,%r9d
call   1070 <Log_Info@plt>
mov    0x10(%rsp),%rax
mov    %ebx,(%rax)
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c">countersum\00"
@.str.1 = [56 x i8] c"set balance of %s to %i by %s [was %i, balance %i] - %s\00"
define i32 @DispenseSet(i32 %0, i32 %1, i32 %2, i8* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32* %4, i32** %11
%15 = load i32, i32* %8
%16 = call i32 @Bank_GetBalance(i32 %15)
store i32 %16, i32* %12
%17 = call i32 @Bank_GetAcctByName(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 1)
%18 = load i32, i32* %8
%19 = load i32, i32* %9
%20 = load i32, i32* %12
%21 = sub nsw i32 %19, %20
%22 = load i8*, i8** %10
%23 = call i64 @Bank_Transfer(i32 %17, i32 %18, i32 %21, i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %5
store i32 -1, i32* %6
br label %45
26: ; preds = %5
%27 = load i32, i32* %7
%28 = call i8* @Bank_GetAcctName(i32 %27)
store i8* %28, i8** %13
%29 = load i32, i32* %8
%30 = call i8* @Bank_GetAcctName(i32 %29)
store i8* %30, i8** %14
%31 = load i8*, i8** %14
%32 = load i32, i32* %9
%33 = load i8*, i8** %13
%34 = load i32, i32* %12
%35 = load i32, i32* %8
%36 = call i32 @Bank_GetBalance(i32 %35)
%37 = load i8*, i8** %10
%38 = call i32 @Log_Info(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %31, i32 %32, i8* %33, i32 %34, i32 %36, i8* %37)
%39 = load i32, i32* %12
%40 = load i32*, i32** %11
store i32 %39, i32* %40
%41 = load i8*, i8** %13
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %14
%44 = call i32 @free(i8* %43)
store i32 0, i32* %6
br label %45
45: ; preds = %26, %25
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@.str = [12 x i8] c">countersum\00"
@.str.1 = [56 x i8] c"set balance of %s to %i by %s [was %i, balance %i] - %s\00"
define i32 @DispenseSet(i32 %0, i32 %1, i32 %2, i8* %3, i32* nocapture writeonly %4) {
%6 = tail call i32 @Bank_GetBalance(i32 %1)
%7 = tail call i32 @Bank_GetAcctByName(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 1)
%8 = sub nsw i32 %2, %6
%9 = tail call i64 @Bank_Transfer(i32 %7, i32 %1, i32 %8, i8* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = tail call i8* @Bank_GetAcctName(i32 %0)
%13 = tail call i8* @Bank_GetAcctName(i32 %1)
%14 = tail call i32 @Bank_GetBalance(i32 %1)
%15 = tail call i32 @Log_Info(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %2, i8* %12, i32 %6, i32 %14, i8* %3)
store i32 %6, i32* %4
%16 = tail call i32 @free(i8* %12)
%17 = tail call i32 @free(i8* %13)
br label %18
18: ; preds = %5, %11
%19 = phi i32 [ 0, %11 ], [ -1, %5 ]
ret i32 %19
}