#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 labs(int);
int /*<<< orphan*/ memset(char *, int, int);
int rand();
void su_use_stack(char *base, long size) {
  char arr[(16 * 1024)];
  char here;
  memset(arr, rand() % 255, (16 * 1024));
  if ((labs(&here - base) + (16 * 1024)) < size) {
    su_use_stack(base, size);
  } else {
    return;
  }
}


x86 assembly (clang, -O0):
<su_use_stack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x4010(%rbp),%rax
mov    %rax,-0x4020(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x4020(%rbp),%rdi
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
mov    $0x4000,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rcx
lea    -0x4011(%rbp),%rax
sub    %rcx,%rax
mov    %eax,%edi
call   1030 <labs@plt>
add    $0x4000,%eax
cltq
cmp    -0x10(%rbp),%rax
jge    11bb <su_use_stack+0x7b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <su_use_stack@plt>
jmp    11c0 <su_use_stack+0x80>
jmp    11c0 <su_use_stack+0x80>
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<su_use_stack>:
push   %r14
push   %rbx
sub    $0x4018,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rsi
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,%ecx
shr    $0x1f,%ecx
sar    $0x7,%esi
add    %ecx,%esi
mov    %esi,%ecx
shl    $0x8,%ecx
sub    %ecx,%esi
add    %eax,%esi
lea    0x10(%rsp),%rdi
mov    $0x4000,%edx
call   1030 <memset@plt>
lea    0xf(%rsp),%rax
sub    %ebx,%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
add    $0x4000,%ecx
cmp    %r14,%rcx
jge    119c <su_use_stack+0x6c>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <su_use_stack@plt>
add    $0x4018,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @su_use_stack(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [16384 x i8]
%6 = alloca i8
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = getelementptr inbounds [16384 x i8], [16384 x i8]* %5, i64 0, i64 0
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 255
%10 = call i32 @memset(i8* %7, i32 %9, i32 16384)
%11 = load i8*, i8** %3
%12 = ptrtoint i8* %6 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = call i32 @labs(i32 %15)
%17 = add nsw i32 %16, 16384
%18 = sext i32 %17 to i64
%19 = load i64, i64* %4
%20 = icmp slt i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i8*, i8** %3
%23 = load i64, i64* %4
br label %25
24: ; preds = %2
br label %25
25: ; preds = %24, %21
ret void
}

LLVM IR (-O2):
define void @su_use_stack(i8* %0, i64 %1) {
%3 = alloca [16384 x i8]
%4 = alloca i8
%5 = getelementptr inbounds [16384 x i8], [16384 x i8]* %3, i64 0, i64 0
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 255
%8 = call i32 @memset(i8* %5, i32 %7, i32 16384)
%9 = ptrtoint i8* %4 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = call i32 @llvm.abs.i32(i32 %12, i1 true)
%14 = add nuw nsw i32 %13, 16384
%15 = zext i32 %14 to i64
%16 = icmp slt i64 %15, %1
br i1 %16, label %17, label %18
17: ; preds = %2
br label %18
18: ; preds = %2, %17
ret void
}