#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 *pyi_getenv(char const *);
scalar_t__ pyi_test_temp_path(char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int pyi_get_temp_path(char *buff) {
  static const char *envname[] = {"TMPDIR", "TEMP", "TMP", 0};
  static const char *dirname[] = {"/tmp", "/var/tmp", "/usr/tmp", 0};
  int i;
  char *p;
  for (i = 0; envname[i]; i++) {
    p = pyi_getenv(envname[i]);
    if (p) {
      strcpy(buff, p);
      if (pyi_test_temp_path(buff)) {
        return 1;
      }
    }
  }
  for (i = 0; dirname[i]; i++) {
    strcpy(buff, dirname[i]);
    if (pyi_test_temp_path(buff)) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<pyi_get_temp_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rcx
lea    0x2ef2(%rip),%rax
cmpq   $0x0,(%rax,%rcx,8)
je     11c0 <pyi_get_temp_path+0x90>
movslq -0x14(%rbp),%rcx
lea    0x2edc(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1050 <pyi_getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ad <pyi_get_temp_path+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <pyi_test_temp_path@plt>
cmp    $0x0,%rax
je     11a8 <pyi_get_temp_path+0x78>
movl   $0x1,-0x4(%rbp)
jmp    122e <pyi_get_temp_path+0xfe>
jmp    11ad <pyi_get_temp_path+0x7d>
jmp    11b2 <pyi_get_temp_path+0x82>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <pyi_get_temp_path+0x13>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rcx
lea    0x2e8e(%rip),%rax
cmpq   $0x0,(%rax,%rcx,8)
je     1227 <pyi_get_temp_path+0xf7>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rcx
lea    0x2e74(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <pyi_test_temp_path@plt>
cmp    $0x0,%rax
je     1214 <pyi_get_temp_path+0xe4>
movl   $0x1,-0x4(%rbp)
jmp    122e <pyi_get_temp_path+0xfe>
jmp    1219 <pyi_get_temp_path+0xe9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c7 <pyi_get_temp_path+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pyi_get_temp_path>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec3(%rip),%rdi
call   1050 <pyi_getenv@plt>
test   %rax,%rax
je     1168 <pyi_get_temp_path+0x38>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <pyi_test_temp_path@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1225 <pyi_get_temp_path+0xf5>
lea    0xe98(%rip),%rdi
call   1050 <pyi_getenv@plt>
test   %rax,%rax
je     119a <pyi_get_temp_path+0x6a>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <pyi_test_temp_path@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1225 <pyi_get_temp_path+0xf5>
lea    0xe6b(%rip),%rdi
call   1050 <pyi_getenv@plt>
test   %rax,%rax
je     11c8 <pyi_get_temp_path+0x98>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <pyi_test_temp_path@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1225 <pyi_get_temp_path+0xf5>
lea    0xe45(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <pyi_test_temp_path@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1225 <pyi_get_temp_path+0xf5>
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <pyi_test_temp_path@plt>
test   %rax,%rax
jne    1225 <pyi_get_temp_path+0xf5>
lea    0xe0d(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <pyi_test_temp_path@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@pyi_get_temp_path.envname = internal global [4 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"TEMP\00"
@.str.2 = [4 x i8] c"TMP\00"
@pyi_get_temp_path.dirname = internal global [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i32 0, i32 0), i8* null]
@.str.3 = [5 x i8] c"/tmp\00"
@.str.4 = [9 x i8] c"/var/tmp\00"
@.str.5 = [9 x i8] c"/usr/tmp\00"
define i32 @pyi_get_temp_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
br label %6
6: ; preds = %30, %1
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [4 x i8*], [4 x i8*]* @pyi_get_temp_path.envname, i64 0, i64 %8
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %33
12: ; preds = %6
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* @pyi_get_temp_path.envname, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = call i8* @pyi_getenv(i8* %16)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %29
20: ; preds = %12
%21 = load i8*, i8** %3
%22 = load i8*, i8** %5
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %3
%25 = call i64 @pyi_test_temp_path(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 1, i32* %2
br label %56
28: ; preds = %20
br label %29
29: ; preds = %28, %12
br label %30
30: ; preds = %29
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %6
33: ; preds = %6
store i32 0, i32* %4
br label %34
34: ; preds = %52, %33
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [4 x i8*], [4 x i8*]* @pyi_get_temp_path.dirname, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %55
40: ; preds = %34
%41 = load i8*, i8** %3
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [4 x i8*], [4 x i8*]* @pyi_get_temp_path.dirname, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @strcpy(i8* %41, i8* %45)
%47 = load i8*, i8** %3
%48 = call i64 @pyi_test_temp_path(i8* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %40
store i32 1, i32* %2
br label %56
51: ; preds = %40
br label %52
52: ; preds = %51
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %34
55: ; preds = %34
store i32 0, i32* %2
br label %56
56: ; preds = %55, %50, %27
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"TEMP\00"
@.str.2 = [4 x i8] c"TMP\00"
@.str.3 = [5 x i8] c"/tmp\00"
@.str.4 = [9 x i8] c"/var/tmp\00"
@.str.5 = [9 x i8] c"/usr/tmp\00"
define i32 @pyi_get_temp_path(i8* %0) {
%2 = tail call i8* @pyi_getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i32 @strcpy(i8* %0, i8* %2)
%6 = tail call i64 @pyi_test_temp_path(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %35
8: ; preds = %1, %4
%9 = tail call i8* @pyi_getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i32 @strcpy(i8* %0, i8* %9)
%13 = tail call i64 @pyi_test_temp_path(i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %35
15: ; preds = %11, %8
%16 = tail call i8* @pyi_getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = tail call i32 @strcpy(i8* %0, i8* %16)
%20 = tail call i64 @pyi_test_temp_path(i8* %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %18, %15
%23 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%24 = tail call i64 @pyi_test_temp_path(i8* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%28 = tail call i64 @pyi_test_temp_path(i8* %0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%32 = tail call i64 @pyi_test_temp_path(i8* %0)
%33 = icmp ne i64 %32, 0
%34 = zext i1 %33 to i32
br label %35
35: ; preds = %30, %4, %11, %18, %22, %26
%36 = phi i32 [ 1, %22 ], [ 1, %26 ], [ 1, %18 ], [ 1, %11 ], [ 1, %4 ], [ %34, %30 ]
ret i32 %36
}