#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 rand();
void *thread_start(void *arg) {
  int *stack_usage = (int *)arg;
  if (*stack_usage > 0) {
    char dummy_data[*stack_usage];
    for (int i = 0; i < *stack_usage; i++) {
      dummy_data[i] = (dummy_data[i] + rand()) & 0xff;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<thread_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11b8 <thread_start+0xa8>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    11b1 <thread_start+0xa1>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x34(%rbp),%ecx
mov    %al,%dl
mov    -0x30(%rbp),%rax
movsbl %dl,%edx
add    %edx,%ecx
and    $0xff,%ecx
mov    %cl,%dl
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <thread_start+0x51>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_start>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%eax
test   %eax,%eax
jle    1182 <thread_start+0x72>
mov    %rdi,%r15
mov    %rsp,%r14
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmpl   $0x0,(%rdi)
jle    117f <thread_start+0x6f>
xor    %eax,%eax
call   1030 <rand@plt>
cmpl   $0x2,(%r15)
jl     117f <thread_start+0x6f>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r12,%rbx,1),%r13d
xor    %eax,%eax
call   1030 <rand@plt>
add    %r13b,%al
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
movslq (%r15),%rax
cmp    %rax,%rbx
jl     1160 <thread_start+0x50>
mov    %r14,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @thread_start(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = load i32, i32* %9
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %42
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = load i32, i32* %13
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %4
%17 = alloca i8, i64 %15
store i64 %15, i64* %5
store i32 0, i32* %6
br label %18
18: ; preds = %37, %12
%19 = load i32, i32* %6
%20 = load i32*, i32** %3
%21 = load i32, i32* %20
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %40
23: ; preds = %18
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %17, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = call signext i8 (...) @rand()
%30 = sext i8 %29 to i32
%31 = add nsw i32 %28, %30
%32 = and i32 %31, 255
%33 = trunc i32 %32 to i8
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %17, i64 %35
store i8 %33, i8* %36
br label %37
37: ; preds = %23
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %18
40: ; preds = %18
%41 = load i8*, i8** %4
br label %42
42: ; preds = %40, %1
ret i8* null
}

LLVM IR (-O2):
define noalias i8* @thread_start(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %27
5: ; preds = %1
%6 = zext i32 %3 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %5
%12 = tail call signext i8 (...) @rand()
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 1
br i1 %14, label %16, label %15
15: ; preds = %16, %11, %5
tail call void @llvm.stackrestore(i8* %7)
br label %27
16: ; preds = %11, %16
%17 = phi i64 [ %23, %16 ], [ 1, %11 ]
%18 = getelementptr inbounds i8, i8* %8, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %8, i64 %17
%21 = tail call signext i8 (...) @rand()
%22 = add i8 %21, %19
store i8 %22, i8* %20
%23 = add nuw nsw i64 %17, 1
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %16, label %15
27: ; preds = %15, %1
ret i8* null
}