#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 c2fString(char *, char *, int);
char *f2cString(char *, int);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int imodgetenv_(char *var, char *value, int varSize, int valueSize) {
  char *valPtr;
  char *cstr = f2cString(var, varSize);
  if (!cstr)
    return -1;
  valPtr = getenv(cstr);
  free(cstr);
  if (!valPtr)
    return 1;
  return c2fString(valPtr, value, valueSize);
}


x86 assembly (clang, -O0):
<imodgetenv_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <f2cString@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    117d <imodgetenv_+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <imodgetenv_+0x7d>
mov    -0x30(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
cmpq   $0x0,-0x28(%rbp)
jne    11aa <imodgetenv_+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    11bd <imodgetenv_+0x7d>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <c2fString@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imodgetenv_>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rsi,%r15
mov    %edx,%esi
call   1060 <f2cString@plt>
test   %rax,%rax
je     118c <imodgetenv_+0x4c>
mov    %rax,%rbp
mov    %rax,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1040 <free@plt>
test   %rbx,%rbx
je     1193 <imodgetenv_+0x53>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <c2fString@plt>
mov    $0xffffffff,%eax
jmp    1198 <imodgetenv_+0x58>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @imodgetenv_(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
%13 = load i32, i32* %8
%14 = call i8* @f2cString(i8* %12, i32 %13)
store i8* %14, i8** %11
%15 = load i8*, i8** %11
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %4
store i32 -1, i32* %5
br label %31
18: ; preds = %4
%19 = load i8*, i8** %11
%20 = call i8* @getenv(i8* %19)
store i8* %20, i8** %10
%21 = load i8*, i8** %11
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %10
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %18
store i32 1, i32* %5
br label %31
26: ; preds = %18
%27 = load i8*, i8** %10
%28 = load i8*, i8** %7
%29 = load i32, i32* %9
%30 = call i32 @c2fString(i8* %27, i8* %28, i32 %29)
store i32 %30, i32* %5
br label %31
31: ; preds = %26, %25, %17
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @imodgetenv_(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i8* @f2cString(i8* %0, i32 %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i8* @getenv(i8* %5)
%9 = tail call i32 @free(i8* %5)
%10 = icmp eq i8* %8, null
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @c2fString(i8* %8, i8* %1, i32 %3)
br label %13
13: ; preds = %7, %4, %11
%14 = phi i32 [ %12, %11 ], [ -1, %4 ], [ 1, %7 ]
ret i32 %14
}