#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 */
typedef int pthread_t;

/* Variables and functions */
int /*<<< orphan*/ escape(int *);
scalar_t__ getenv(char *);
int pthread_self();
int /*<<< orphan*/ usleep(int);
void *threadfunc(void *p) {
  int m[100 * 1024];
  pthread_t tid = pthread_self();
  escape(m);
  if (getenv("USE_MEMORY") != 0) {
    for (int i = 0; i < 100 * 1024; ++i) {
      m[i] = tid % 1000000 + i;
    }
  }
  for (int i = 0; i < 10 * 20; ++i) {
    usleep(50 * 1000);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<threadfunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x64020,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,-0x64014(%rbp)
lea    -0x64010(%rbp),%rdi
call   1050 <escape@plt>
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11d3 <threadfunc+0x93>
movl   $0x0,-0x64018(%rbp)
cmpl   $0x19000,-0x64018(%rbp)
jge    11ce <threadfunc+0x8e>
mov    -0x64014(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
add    -0x64018(%rbp),%edx
movslq -0x64018(%rbp),%rax
mov    %edx,-0x64010(%rbp,%rax,4)
mov    -0x64018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64018(%rbp)
jmp    1188 <threadfunc+0x48>
jmp    11d3 <threadfunc+0x93>
movl   $0x0,-0x6401c(%rbp)
cmpl   $0xc8,-0x6401c(%rbp)
jge    120b <threadfunc+0xcb>
mov    $0xc350,%edi
call   1060 <usleep@plt>
mov    -0x6401c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6401c(%rbp)
jmp    11dd <threadfunc+0x9d>
xor    %eax,%eax
add    $0x64020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<threadfunc>:
push   %rbx
sub    $0x64000,%rsp
xor    %eax,%eax
call   1040 <pthread_self@plt>
mov    %eax,%ebx
mov    %rsp,%rdi
call   1050 <escape@plt>
lea    0xed0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     121b <threadfunc+0xdb>
movslq %ebx,%rax
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%ecx
mov    %eax,%edx
sub    %ecx,%edx
movd   %edx,%xmm0
pshufd $0x0,%xmm0,%xmm0
neg    %ecx
add    %ecx,%eax
add    $0x4,%eax
movd   %eax,%xmm1
pshufd $0x0,%xmm1,%xmm1
movdqa 0xe50(%rip),%xmm2
mov    $0xc,%eax
movdqa 0xe53(%rip),%xmm3
movdqa 0xe5b(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nop
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm1,%xmm6
paddd  %xmm2,%xmm6
movdqa %xmm5,-0x30(%rsp,%rax,4)
movdqa %xmm6,-0x20(%rsp,%rax,4)
movdqa %xmm2,%xmm5
paddd  %xmm3,%xmm5
movdqa %xmm0,%xmm6
paddd  %xmm5,%xmm6
paddd  %xmm1,%xmm5
movdqa %xmm6,-0x10(%rsp,%rax,4)
movdqa %xmm5,(%rsp,%rax,4)
paddd  %xmm4,%xmm2
add    $0x10,%rax
cmp    $0x1900c,%rax
jne    11d0 <threadfunc+0x90>
mov    $0xc8,%ebx
mov    $0xc350,%edi
call   1060 <usleep@plt>
add    $0xffffffff,%ebx
jne    1220 <threadfunc+0xe0>
xor    %eax,%eax
add    $0x64000,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"USE_MEMORY\00"
define noalias i8* @threadfunc(i8* nocapture readnone %0) {
%2 = alloca [102400 x i32]
%3 = bitcast [102400 x i32]* %2 to i8*
%4 = tail call i32 (...) @pthread_self()
%5 = getelementptr inbounds [102400 x i32], [102400 x i32]* %2, i64 0, i64 0
%6 = call i32 @escape(i32* %5)
%7 = call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %20, %1
br label %41
10: ; preds = %1
%11 = srem i32 %4, 1000000
%12 = insertelement <4 x i32> poison, i32 %11, i64 0
%13 = shufflevector <4 x i32> %12, <4 x i32> poison, <4 x i32> zeroinitializer
%14 = add nsw i32 %11, 4
%15 = insertelement <4 x i32> poison, i32 %14, i64 0
%16 = shufflevector <4 x i32> %15, <4 x i32> poison, <4 x i32> zeroinitializer
%17 = add nsw i32 %11, 4
%18 = insertelement <4 x i32> poison, i32 %17, i64 0
%19 = shufflevector <4 x i32> %18, <4 x i32> poison, <4 x i32> zeroinitializer
br label %20
20: ; preds = %20, %10
%21 = phi i64 [ 0, %10 ], [ %37, %20 ]
%22 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %10 ], [ %38, %20 ]
%23 = getelementptr inbounds [102400 x i32], [102400 x i32]* %2, i64 0, i64 %21
%24 = add <4 x i32> %13, %22
%25 = add <4 x i32> %16, %22
%26 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %24, <4 x i32>* %26
%27 = getelementptr inbounds i32, i32* %23, i64 4
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> %25, <4 x i32>* %28
%29 = or i64 %21, 8
%30 = add <4 x i32> %22, <i32 8, i32 8, i32 8, i32 8>
%31 = getelementptr inbounds [102400 x i32], [102400 x i32]* %2, i64 0, i64 %29
%32 = add <4 x i32> %13, %30
%33 = add <4 x i32> %19, %30
%34 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> %32, <4 x i32>* %34
%35 = getelementptr inbounds i32, i32* %31, i64 4
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> %33, <4 x i32>* %36
%37 = add nuw nsw i64 %21, 16
%38 = add <4 x i32> %22, <i32 16, i32 16, i32 16, i32 16>
%39 = icmp eq i64 %37, 102400
br i1 %39, label %9, label %20
40: ; preds = %41
ret i8* null
41: ; preds = %9, %41
%42 = phi i32 [ %44, %41 ], [ 0, %9 ]
%43 = call i32 @usleep(i32 50000)
%44 = add nuw nsw i32 %42, 1
%45 = icmp eq i32 %44, 200
br i1 %45, label %40, label %41
}