#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int GetCurrentDirectory(int, char *);
int /*<<< orphan*/ GetLastError();
int /*<<< orphan*/ debug_tools(char *, int /*<<< orphan*/);
char toupper(char);
int query_drive(void) {
  char buf[260];
  int drive, rc;
  rc = GetCurrentDirectory(sizeof(buf), buf);
  debug_tools("rc = %d after GetCurrentDirectory; error = %d\n",
              GetLastError());
  drive = toupper(buf[0]) - 'A';
  return (drive < 0 || drive > 25) ? 0 : drive;
}


x86 assembly (clang, -O0):
<query_drive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rsi
mov    $0x104,%edi
call   1050 <GetCurrentDirectory@plt>
mov    %eax,-0x118(%rbp)
mov    $0x0,%al
call   1060 <GetLastError@plt>
mov    %eax,%esi
lea    0xe8e(%rip),%rdi
call   1040 <debug_tools@plt>
movsbl -0x110(%rbp),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jl     11a9 <query_drive+0x69>
cmpl   $0x19,-0x114(%rbp)
jle    11b6 <query_drive+0x76>
xor    %eax,%eax
mov    %eax,-0x11c(%rbp)
jmp    11c2 <query_drive+0x82>
mov    -0x114(%rbp),%eax
mov    %eax,-0x11c(%rbp)
mov    -0x11c(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<query_drive>:
push   %rbx
sub    $0x110,%rsp
mov    %rsp,%rsi
mov    $0x104,%edi
call   1050 <GetCurrentDirectory@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <GetLastError@plt>
lea    0xe9b(%rip),%rdi
mov    %eax,%esi
call   1040 <debug_tools@plt>
movsbl (%rsp),%edi
call   1030 <toupper@plt>
movsbl %al,%ecx
lea    -0x41(%rcx),%eax
add    $0xa5,%cl
cmp    $0xe6,%cl
cmovb  %ebx,%eax
add    $0x110,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [47 x i8] c"rc = %d after GetCurrentDirectory; error = %d\0A\00"
define i32 @query_drive() {
%1 = alloca [260 x i8]
%2 = getelementptr inbounds [260 x i8], [260 x i8]* %1, i64 0, i64 0
%3 = call i32 @GetCurrentDirectory(i32 260, i8* %2)
%4 = call i32 (...) @GetLastError()
%5 = call i32 @debug_tools(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i8, i8* %2
%7 = call signext i8 @toupper(i8 signext %6)
%8 = sext i8 %7 to i32
%9 = add nsw i32 %8, -65
%10 = add i8 %7, -91
%11 = icmp ult i8 %10, -26
%12 = select i1 %11, i32 0, i32 %9
ret i32 %12
}