#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 */
char *ModelicaAllocateString(int /*<<< orphan*/);
char *getenv(char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
const char *ModelicaInternal_getenv(const char *name, int convertToSlash,
                                    int *exist) {
  char *value = getenv(name);
  char *result;
  if (value == NULL) {
    result = ModelicaAllocateString(0);
    result[0] = '\0';
    *exist = 0;
  } else {
    result = ModelicaAllocateString(strlen(value));
    strcpy(result, value);
    if (convertToSlash == 1)
      ;
    ;
    *exist = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<ModelicaInternal_getenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118c <ModelicaInternal_getenv+0x4c>
xor    %edi,%edi
call   1060 <ModelicaAllocateString@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    11c6 <ModelicaInternal_getenv+0x86>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1060 <ModelicaAllocateString@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
cmpl   $0x1,-0xc(%rbp)
jne    11bc <ModelicaInternal_getenv+0x7c>
jmp    11bc <ModelicaInternal_getenv+0x7c>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ModelicaInternal_getenv>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
call   1030 <getenv@plt>
test   %rax,%rax
je     1179 <ModelicaInternal_getenv+0x39>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1060 <ModelicaAllocateString@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    $0x1,%ebx
jmp    1188 <ModelicaInternal_getenv+0x48>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <ModelicaAllocateString@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %ebx,(%r14)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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