#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 *my_getenv(int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, ...);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ usleep(int);
void *thr_fun(void *arg) {
  int n, i;
  for (n = 0; n < 3; ++n) {
    for (i = 0; i < 3; ++i) {
      int ret = 0;
      char const *envstr = my_getenv(i);
      if (envstr)
        printf("[%lu] %s\n", pthread_self(), envstr);
      else
        printf("[%lu] %d not found, ret %d\n", pthread_self(), i, ret);
    }
    usleep(100000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<thr_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    11f4 <thr_fun+0xb4>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    11dc <thr_fun+0x9c>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <my_getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ac <thr_fun+0x6c>
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c9 <thr_fun+0x89>
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ce <thr_fun+0x8e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1164 <thr_fun+0x24>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1153 <thr_fun+0x13>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thr_fun>:
push   %rbx
xor    %edi,%edi
call   1040 <my_getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
test   %rbx,%rbx
je     116c <thr_fun+0x2c>
lea    0xea2(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1180 <thr_fun+0x40>
lea    0xe97(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <my_getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
test   %rbx,%rbx
je     11ae <thr_fun+0x6e>
lea    0xe60(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c5 <thr_fun+0x85>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <my_getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
test   %rbx,%rbx
je     11f3 <thr_fun+0xb3>
lea    0xe1b(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    120a <thr_fun+0xca>
lea    0xe10(%rip),%rdi
mov    %eax,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
xor    %edi,%edi
call   1040 <my_getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
test   %rbx,%rbx
je     123f <thr_fun+0xff>
lea    0xdcf(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1253 <thr_fun+0x113>
lea    0xdc4(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <my_getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
test   %rbx,%rbx
je     1281 <thr_fun+0x141>
lea    0xd8d(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1298 <thr_fun+0x158>
lea    0xd82(%rip),%rdi
mov    %eax,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <my_getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
test   %rbx,%rbx
je     12c6 <thr_fun+0x186>
lea    0xd48(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12dd <thr_fun+0x19d>
lea    0xd3d(%rip),%rdi
mov    %eax,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
xor    %edi,%edi
call   1040 <my_getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
test   %rbx,%rbx
je     1312 <thr_fun+0x1d2>
lea    0xcfc(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1326 <thr_fun+0x1e6>
lea    0xcf1(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <my_getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
test   %rbx,%rbx
je     1354 <thr_fun+0x214>
lea    0xcba(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    136b <thr_fun+0x22b>
lea    0xcaf(%rip),%rdi
mov    %eax,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <my_getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
test   %rbx,%rbx
je     1399 <thr_fun+0x259>
lea    0xc75(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    13b0 <thr_fun+0x270>
lea    0xc6a(%rip),%rdi
mov    %eax,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"[%lu] %s\0A\00"
@.str.1 = [28 x i8] c"[%lu] %d not found, ret %d\0A\00"
define i8* @thr_fun(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
br label %7
7: ; preds = %34, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %37
10: ; preds = %7
store i32 0, i32* %4
br label %11
11: ; preds = %29, %10
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %32
14: ; preds = %11
store i32 0, i32* %5
%15 = load i32, i32* %4
%16 = call i8* @my_getenv(i32 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = call i32 (...) @pthread_self()
%21 = load i8*, i8** %6
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %21)
br label %28
23: ; preds = %14
%24 = call i32 (...) @pthread_self()
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25, i32 %26)
br label %28
28: ; preds = %23, %19
br label %29
29: ; preds = %28
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %11
32: ; preds = %11
%33 = call i32 @usleep(i32 100000)
br label %34
34: ; preds = %32
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %7
37: ; preds = %7
ret i8* null
}

LLVM IR (-O2):
@.str = [10 x i8] c"[%lu] %s\0A\00"
@.str.1 = [28 x i8] c"[%lu] %d not found, ret %d\0A\00"
define noalias i8* @thr_fun(i8* nocapture readnone %0) {
%2 = tail call i8* @my_getenv(i32 0)
%3 = icmp eq i8* %2, null
%4 = tail call i32 (...) @pthread_self()
br i1 %3, label %7, label %5
5: ; preds = %1
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4, i8* %2)
br label %9
7: ; preds = %1
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 0, i32 0)
br label %9
9: ; preds = %7, %5
%10 = tail call i8* @my_getenv(i32 1)
%11 = icmp eq i8* %10, null
%12 = tail call i32 (...) @pthread_self()
br i1 %11, label %15, label %13
13: ; preds = %9
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %10)
br label %17
15: ; preds = %9
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 1, i32 0)
br label %17
17: ; preds = %15, %13
%18 = tail call i8* @my_getenv(i32 2)
%19 = icmp eq i8* %18, null
%20 = tail call i32 (...) @pthread_self()
br i1 %19, label %23, label %21
21: ; preds = %17
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %18)
br label %25
23: ; preds = %17
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 2, i32 0)
br label %25
25: ; preds = %23, %21
%26 = tail call i32 @usleep(i32 100000)
%27 = tail call i8* @my_getenv(i32 0)
%28 = icmp eq i8* %27, null
%29 = tail call i32 (...) @pthread_self()
br i1 %28, label %32, label %30
30: ; preds = %25
%31 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %29, i8* %27)
br label %34
32: ; preds = %25
%33 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 0, i32 0)
br label %34
34: ; preds = %32, %30
%35 = tail call i8* @my_getenv(i32 1)
%36 = icmp eq i8* %35, null
%37 = tail call i32 (...) @pthread_self()
br i1 %36, label %40, label %38
38: ; preds = %34
%39 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %37, i8* %35)
br label %42
40: ; preds = %34
%41 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 1, i32 0)
br label %42
42: ; preds = %40, %38
%43 = tail call i8* @my_getenv(i32 2)
%44 = icmp eq i8* %43, null
%45 = tail call i32 (...) @pthread_self()
br i1 %44, label %48, label %46
46: ; preds = %42
%47 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %45, i8* %43)
br label %50
48: ; preds = %42
%49 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %45, i32 2, i32 0)
br label %50
50: ; preds = %48, %46
%51 = tail call i32 @usleep(i32 100000)
%52 = tail call i8* @my_getenv(i32 0)
%53 = icmp eq i8* %52, null
%54 = tail call i32 (...) @pthread_self()
br i1 %53, label %57, label %55
55: ; preds = %50
%56 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %54, i8* %52)
br label %59
57: ; preds = %50
%58 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %54, i32 0, i32 0)
br label %59
59: ; preds = %57, %55
%60 = tail call i8* @my_getenv(i32 1)
%61 = icmp eq i8* %60, null
%62 = tail call i32 (...) @pthread_self()
br i1 %61, label %65, label %63
63: ; preds = %59
%64 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %62, i8* %60)
br label %67
65: ; preds = %59
%66 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %62, i32 1, i32 0)
br label %67
67: ; preds = %65, %63
%68 = tail call i8* @my_getenv(i32 2)
%69 = icmp eq i8* %68, null
%70 = tail call i32 (...) @pthread_self()
br i1 %69, label %73, label %71
71: ; preds = %67
%72 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %70, i8* %68)
br label %75
73: ; preds = %67
%74 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %70, i32 2, i32 0)
br label %75
75: ; preds = %73, %71
%76 = tail call i32 @usleep(i32 100000)
ret i8* null
}