#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 myMessageBox(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int shell_q_overwrite(const char *name) {
  int ret = 0;
  char tmptxt[260];
  sprintf(tmptxt, "File '%s' already exists. Do you want to overwrite it?",
          name);
  switch (myMessageBox(tmptxt, 4)) {
  case 3:
    ret = 2;
    break;
  case 4:
    ret = 1;
    break;
  case 2:
    ret = 0;
    break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<shell_q_overwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdx
lea    0xebf(%rip),%rsi
lea    -0x110(%rbp),%rdi
mov    %rdi,-0x120(%rbp)
call   1030 <sprintf@plt>
mov    -0x120(%rbp),%rdi
mov    $0x4,%esi
call   1040 <myMessageBox@plt>
mov    %eax,%ecx
mov    %ecx,-0x114(%rbp)
sub    $0x2,%eax
je     11bb <shell_q_overwrite+0x9b>
jmp    117b <shell_q_overwrite+0x5b>
mov    -0x114(%rbp),%eax
sub    $0x3,%eax
je     11a3 <shell_q_overwrite+0x83>
jmp    118f <shell_q_overwrite+0x6f>
mov    -0x114(%rbp),%eax
sub    $0x4,%eax
je     11af <shell_q_overwrite+0x8f>
jmp    11c2 <shell_q_overwrite+0xa2>
movl   $0x2,-0xc(%rbp)
jmp    11c2 <shell_q_overwrite+0xa2>
movl   $0x1,-0xc(%rbp)
jmp    11c2 <shell_q_overwrite+0xa2>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shell_q_overwrite>:
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%rdx
lea    0xece(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <myMessageBox@plt>
xor    %ecx,%ecx
cmp    $0x4,%eax
sete   %cl
cmp    $0x3,%eax
mov    $0x2,%eax
cmovne %ecx,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [55 x i8] c"File '%s' already exists. Do you want to overwrite it?\00"
define i32 @shell_q_overwrite(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [260 x i8]
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = getelementptr inbounds [260 x i8], [260 x i8]* %4, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [260 x i8], [260 x i8]* %4, i64 0, i64 0
%9 = call i32 @myMessageBox(i8* %8, i32 4)
switch i32 %9, label %13 [
i32 3, label %10
i32 4, label %11
i32 2, label %12
]
10: ; preds = %1
store i32 2, i32* %3
br label %13
11: ; preds = %1
store i32 1, i32* %3
br label %13
12: ; preds = %1
store i32 0, i32* %3
br label %13
13: ; preds = %1, %12, %11, %10
%14 = load i32, i32* %3
ret i32 %14
}

LLVM IR (-O2):
@.str = [55 x i8] c"File '%s' already exists. Do you want to overwrite it?\00"
define i32 @shell_q_overwrite(i8* %0) {
%2 = alloca [260 x i8]
%3 = getelementptr inbounds [260 x i8], [260 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32 @myMessageBox(i8* %3, i32 4)
%6 = icmp eq i32 %5, 4
%7 = zext i1 %6 to i32
%8 = icmp eq i32 %5, 3
%9 = select i1 %8, i32 2, i32 %7
ret i32 %9
}