#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 */
scalar_t__ GetCurrentDirectoryA(int, char *);
scalar_t__ SHGetFolderPathA(int /*<<< orphan*/, int, int /*<<< orphan*/,
                            int /*<<< orphan*/, char *);
char *getenv(char const *);
scalar_t__ strcmp(char const *, char *);
char *Win32_getenv(const char *name) {
  static char env[260];
  env[0] = 0;
  if (strcmp(name, "PWD") == 0) {
    if (GetCurrentDirectoryA(260, env) > 0)
      return env;
  } else if (strcmp(name, "HOME") == 0) {
    if (SHGetFolderPathA(0, 5, 0, 0, env) == 0)
      return env;
  }
  return getenv(name);
}


x86 assembly (clang, -O0):
<Win32_getenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x0,0x2efd(%rip)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    119d <Win32_getenv+0x5d>
mov    $0x104,%edi
lea    0x2ed7(%rip),%rsi
call   1040 <GetCurrentDirectoryA@plt>
cmp    $0x0,%rax
jle    1198 <Win32_getenv+0x58>
lea    0x2ec1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ff <Win32_getenv+0xbf>
jmp    11f2 <Win32_getenv+0xb2>
mov    -0x10(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ed <Win32_getenv+0xad>
xor    %ecx,%ecx
mov    $0x5,%esi
lea    0x2e8b(%rip),%r8
mov    %ecx,%edi
mov    %ecx,%edx
call   1060 <SHGetFolderPathA@plt>
cmp    $0x0,%rax
jne    11e8 <Win32_getenv+0xa8>
lea    0x2e71(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ff <Win32_getenv+0xbf>
jmp    11ed <Win32_getenv+0xad>
jmp    11f2 <Win32_getenv+0xb2>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Win32_getenv>:
push   %rbx
mov    %rdi,%rbx
movb   $0x0,0x2f05(%rip)
lea    0xeae(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1195 <Win32_getenv+0x55>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    118c <Win32_getenv+0x4c>
lea    0x2ed9(%rip),%r8
xor    %edi,%edi
mov    $0x5,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <SHGetFolderPathA@plt>
test   %rax,%rax
je     11ab <Win32_getenv+0x6b>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <getenv@plt>
lea    0x2eb4(%rip),%rsi
mov    $0x104,%edi
call   1040 <GetCurrentDirectoryA@plt>
test   %rax,%rax
jle    118c <Win32_getenv+0x4c>
lea    0x2e9e(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@Win32_getenv.env = internal global [260 x i8] zeroinitializer
@.str = [4 x i8] c"PWD\00"
@.str.1 = [5 x i8] c"HOME\00"
define i8* @Win32_getenv(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
store i8 0, i8* getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0)
%4 = load i8*, i8** %3
%5 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = call i64 @GetCurrentDirectoryA(i32 260, i8* getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0))
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %7
store i8* getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0), i8** %2
br label %25
11: ; preds = %7
br label %22
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = call i64 @SHGetFolderPathA(i32 0, i32 5, i32 0, i32 0, i8* getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i8* getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0), i8** %2
br label %25
20: ; preds = %16
br label %21
21: ; preds = %20, %12
br label %22
22: ; preds = %21, %11
%23 = load i8*, i8** %3
%24 = call i8* @getenv(i8* %23)
store i8* %24, i8** %2
br label %25
25: ; preds = %22, %19, %10
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@Win32_getenv.env = internal global [260 x i8] zeroinitializer
@.str = [4 x i8] c"PWD\00"
@.str.1 = [5 x i8] c"HOME\00"
define i8* @Win32_getenv(i8* %0) {
store i8 0, i8* getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0)
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i64 @GetCurrentDirectoryA(i32 260, i8* getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0))
%6 = icmp sgt i64 %5, 0
br i1 %6, label %15, label %13
7: ; preds = %1
%8 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i64 @SHGetFolderPathA(i32 0, i32 5, i32 0, i32 0, i8* getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7, %10, %4
%14 = tail call i8* @getenv(i8* %0)
br label %15
15: ; preds = %10, %4, %13
%16 = phi i8* [ %14, %13 ], [ getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0), %4 ], [ getelementptr inbounds ([260 x i8], [260 x i8]* @Win32_getenv.env, i64 0, i64 0), %10 ]
ret i8* %16
}