#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 gp_getenv(char *, char *, int *);
int gp_gettmpdir(char *ptr, int *plen) {
  int max_len = *plen;
  int code = gp_getenv("TMPDIR", ptr, plen);
  if (code != 1)
    return code;
  *plen = max_len;
  return gp_getenv("TEMP", ptr, plen);
}


x86 assembly (clang, -O0):
<gp_gettmpdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xec8(%rip),%rdi
call   1030 <gp_getenv@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
je     1155 <gp_gettmpdir+0x45>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <gp_gettmpdir+0x65>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe9a(%rip),%rdi
call   1030 <gp_getenv@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gp_gettmpdir>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%ebp
lea    0xedd(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <gp_getenv@plt>
cmp    $0x1,%eax
jne    114b <gp_gettmpdir+0x3b>
mov    %ebp,(%rbx)
lea    0xecb(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <gp_getenv@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"TEMP\00"
define i32 @gp_gettmpdir(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
%9 = load i32, i32* %8
store i32 %9, i32* %6
%10 = load i8*, i8** %4
%11 = load i32*, i32** %5
%12 = call i32 @gp_getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %10, i32* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i32, i32* %7
store i32 %16, i32* %3
br label %23
17: ; preds = %2
%18 = load i32, i32* %6
%19 = load i32*, i32** %5
store i32 %18, i32* %19
%20 = load i8*, i8** %4
%21 = load i32*, i32** %5
%22 = call i32 @gp_getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32* %21)
store i32 %22, i32* %3
br label %23
23: ; preds = %17, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"TEMP\00"
define i32 @gp_gettmpdir(i8* %0, i32* %1) {
%3 = load i32, i32* %1
%4 = tail call i32 @gp_getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i32* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %2
store i32 %3, i32* %1
%7 = tail call i32 @gp_getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* %1)
br label %8
8: ; preds = %2, %6
%9 = phi i32 [ %7, %6 ], [ %4, %2 ]
ret i32 %9
}