#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*/ cygwin32_conv_to_win32_path(char *, char *);
int cygwin32_posix_to_win32_path_list_buf_size(char *);
int /*<<< orphan*/ free(char *);
char *getenv(char const *);
char *malloc(int);
int /*<<< orphan*/ setenv(char const *, char *, int);
void fixenv(const char *envname) {
  char *winval;
  int newlen;
  char *env;
  env = getenv(envname);
  if (env && env[0] != '\0') {
    int len = cygwin32_posix_to_win32_path_list_buf_size(env);
    winval = malloc(len);
    cygwin32_conv_to_win32_path(env, winval);
    setenv(envname, winval, 1);
    free(winval);
  }
}


x86 assembly (clang, -O0):
<fixenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d4 <fixenv+0x74>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d4 <fixenv+0x74>
mov    -0x20(%rbp),%rdi
call   1080 <cygwin32_posix_to_win32_path_list_buf_size@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <cygwin32_conv_to_win32_path@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1060 <setenv@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixenv>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <getenv@plt>
test   %rax,%rax
je     11b4 <fixenv+0x54>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11b4 <fixenv+0x54>
mov    %rbx,%rdi
call   1080 <cygwin32_posix_to_win32_path_list_buf_size@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <cygwin32_conv_to_win32_path@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <setenv@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <free@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @fixenv(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @getenv(i8* %7)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %30
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %11
%18 = load i8*, i8** %5
%19 = call i32 @cygwin32_posix_to_win32_path_list_buf_size(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %3
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = call i32 @cygwin32_conv_to_win32_path(i8* %22, i8* %23)
%25 = load i8*, i8** %2
%26 = load i8*, i8** %3
%27 = call i32 @setenv(i8* %25, i8* %26, i32 1)
%28 = load i8*, i8** %3
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %17, %11, %1
ret void
}

LLVM IR (-O2):
define void @fixenv(i8* %0) {
%2 = tail call i8* @getenv(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i32 @cygwin32_posix_to_win32_path_list_buf_size(i8* %2)
%9 = tail call i8* @malloc(i32 %8)
%10 = tail call i32 @cygwin32_conv_to_win32_path(i8* %2, i8* %9)
%11 = tail call i32 @setenv(i8* %0, i8* %9, i32 1)
%12 = tail call i32 @free(i8* %9)
br label %13
13: ; preds = %7, %4, %1
ret void
}