#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*/ GetLastError();
scalar_t__ SetCurrentDirectory(char *);
int /*<<< orphan*/ debug_tools(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int change_drive(int drive) {
  char buf[3];
  int rc;
  if (drive < 0 || drive > 25)
    drive = 0;
  strcpy(buf, "A:");
  buf[0] = drive + 'A';
  rc = SetCurrentDirectory(buf) ? 0 : -1;
  debug_tools("rc = %d after SetCurrentDirectory; error = %d\n",
              GetLastError());
  return rc;
}


x86 assembly (clang, -O0):
<change_drive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     115f <change_drive+0x1f>
cmpl   $0x19,-0x4(%rbp)
jle    1166 <change_drive+0x26>
movl   $0x0,-0x4(%rbp)
lea    -0x7(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x4(%rbp),%eax
add    $0x41,%eax
mov    %al,-0x7(%rbp)
lea    -0x7(%rbp),%rdi
call   1030 <SetCurrentDirectory@plt>
mov    %rax,%rdx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1060 <GetLastError@plt>
mov    %eax,%esi
lea    0xe57(%rip),%rdi
call   1050 <debug_tools@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_drive>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xeb3(%rip),%rsi
lea    0x5(%rsp),%r14
mov    %r14,%rdi
call   1040 <strcpy@plt>
lea    0x41(%rbx),%eax
cmp    $0x1a,%ebx
movzbl %al,%eax
mov    $0x41,%ecx
cmovb  %eax,%ecx
mov    %cl,0x5(%rsp)
mov    %r14,%rdi
call   1030 <SetCurrentDirectory@plt>
cmp    $0x1,%rax
sbb    %ebx,%ebx
xor    %eax,%eax
call   1060 <GetLastError@plt>
lea    0xe78(%rip),%rdi
mov    %eax,%esi
call   1050 <debug_tools@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"A:\00"
@.str.1 = [47 x i8] c"rc = %d after SetCurrentDirectory; error = %d\0A\00"
define i32 @change_drive(i32 %0) {
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp sgt i32 %8, 25
br i1 %9, label %10, label %11
10: ; preds = %7, %1
store i32 0, i32* %2
br label %11
11: ; preds = %10, %7
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 65
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
store i8 %16, i8* %17
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%19 = call i64 @SetCurrentDirectory(i8* %18)
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 0, i32 -1
store i32 %22, i32* %4
%23 = call i32 (...) @GetLastError()
%24 = call i32 @debug_tools(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@.str = [3 x i8] c"A:\00"
@.str.1 = [47 x i8] c"rc = %d after SetCurrentDirectory; error = %d\0A\00"
define i32 @change_drive(i32 %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = icmp ugt i32 %0, 25
%5 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = trunc i32 %0 to i8
%7 = add i8 %6, 65
%8 = select i1 %4, i8 65, i8 %7
store i8 %8, i8* %3
%9 = call i64 @SetCurrentDirectory(i8* %3)
%10 = icmp eq i64 %9, 0
%11 = sext i1 %10 to i32
%12 = call i32 (...) @GetLastError()
%13 = call i32 @debug_tools(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %12)
ret i32 %11
}