#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*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
int withdraw(int);
void *try_to_withdraw(void *tid) {
  int *thread_id = (int *)tid;
  sleep(2);
  printf("T %d: trying to withdraw %d\n", *thread_id, 35);
  if (withdraw(35) == 35)
    printf("T %d: Successfully withdrawn\n", *thread_id);
  else
    printf("T %d: Failed to withdraw\n", *thread_id);
  return NULL;
}


x86 assembly (clang, -O0):
<try_to_withdraw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x2,%edi
call   1050 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
mov    $0x23,%edx
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x23,%edi
call   1030 <withdraw@plt>
cmp    $0x23,%eax
jne    1193 <try_to_withdraw+0x63>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a7 <try_to_withdraw+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try_to_withdraw>:
push   %rbx
mov    %rdi,%rbx
mov    $0x2,%edi
call   1050 <sleep@plt>
mov    (%rbx),%esi
lea    0xeb9(%rip),%rdi
mov    $0x23,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x23,%edi
call   1030 <withdraw@plt>
cmp    $0x23,%eax
mov    (%rbx),%esi
lea    0xeb4(%rip),%rax
lea    0xecb(%rip),%rdi
cmove  %rax,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"T %d: trying to withdraw %d\0A\00"
@.str.1 = [30 x i8] c"T %d: Successfully withdrawn\0A\00"
@.str.2 = [26 x i8] c"T %d: Failed to withdraw\0A\00"
define i8* @try_to_withdraw(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = bitcast i8* %4 to i32*
store i32* %5, i32** %3
%6 = call i32 @sleep(i32 2)
%7 = load i32*, i32** %3
%8 = load i32, i32* %7
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %8, i32 35)
%10 = call i32 @withdraw(i32 35)
%11 = icmp eq i32 %10, 35
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = load i32, i32* %13
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %20
16: ; preds = %1
%17 = load i32*, i32** %3
%18 = load i32, i32* %17
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %12
ret i8* null
}

LLVM IR (-O2):
@.str = [29 x i8] c"T %d: trying to withdraw %d\0A\00"
@.str.1 = [30 x i8] c"T %d: Successfully withdrawn\0A\00"
@.str.2 = [26 x i8] c"T %d: Failed to withdraw\0A\00"
define noalias i8* @try_to_withdraw(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = tail call i32 @sleep(i32 2)
%4 = load i32, i32* %2
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %4, i32 35)
%6 = tail call i32 @withdraw(i32 35)
%7 = icmp eq i32 %6, 35
%8 = load i32, i32* %2
%9 = select i1 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0)
%10 = tail call i32 (i8*, i32, ...) @printf(i8* %9, i32 %8)
ret i8* null
}