#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 random();
int /*<<< orphan*/ setenv(char *, char *, int);
void *worker(void *arg) {
  for (;;) {
    int i;
    char var[256], *p = var;
    for (i = 0; i < 8; ++i) {
      *p++ = 65 + (random() % 26);
    }
    *p++ = '\0';
    setenv(var, "test", 1);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<worker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1187 <worker+0x67>
mov    $0x0,%al
call   1040 <random@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %dl,%cl
mov    -0x118(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x118(%rbp)
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <worker+0x24>
mov    -0x118(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x118(%rbp)
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
jmp    112f <worker+0xf>

x86 assembly (clang, -O2):
<worker>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xecf(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,0x1(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,0x2(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,0x3(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,0x4(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,0x5(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,0x6(%rsp)
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,0x7(%rsp)
movb   $0x0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
jmp    1140 <worker+0x20>

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
define i8* @worker(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
br label %6
6: ; preds = %21, %1
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8* %7, i8** %5
store i32 0, i32* %3
br label %8
8: ; preds = %18, %6
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 8
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = call i32 (...) @random()
%13 = srem i32 %12, 26
%14 = add nsw i32 65, %13
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %5
store i8 %15, i8* %16
br label %18
18: ; preds = %11
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %8
21: ; preds = %8
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
store i8 0, i8* %22
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = call i32 @setenv(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
br label %6
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
define noalias i8* @worker(i8* nocapture readnone %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 1
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 3
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 4
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 5
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 6
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 7
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 8
br label %12
12: ; preds = %12, %1
%13 = call i32 (...) @random()
%14 = srem i32 %13, 26
%15 = trunc i32 %14 to i8
%16 = add nsw i8 %15, 65
store i8 %16, i8* %3
%17 = call i32 (...) @random()
%18 = srem i32 %17, 26
%19 = trunc i32 %18 to i8
%20 = add nsw i8 %19, 65
store i8 %20, i8* %4
%21 = call i32 (...) @random()
%22 = srem i32 %21, 26
%23 = trunc i32 %22 to i8
%24 = add nsw i8 %23, 65
store i8 %24, i8* %5
%25 = call i32 (...) @random()
%26 = srem i32 %25, 26
%27 = trunc i32 %26 to i8
%28 = add nsw i8 %27, 65
store i8 %28, i8* %6
%29 = call i32 (...) @random()
%30 = srem i32 %29, 26
%31 = trunc i32 %30 to i8
%32 = add nsw i8 %31, 65
store i8 %32, i8* %7
%33 = call i32 (...) @random()
%34 = srem i32 %33, 26
%35 = trunc i32 %34 to i8
%36 = add nsw i8 %35, 65
store i8 %36, i8* %8
%37 = call i32 (...) @random()
%38 = srem i32 %37, 26
%39 = trunc i32 %38 to i8
%40 = add nsw i8 %39, 65
store i8 %40, i8* %9
%41 = call i32 (...) @random()
%42 = srem i32 %41, 26
%43 = trunc i32 %42 to i8
%44 = add nsw i8 %43, 65
store i8 %44, i8* %10
store i8 0, i8* %11
%45 = call i32 @setenv(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
br label %12
}