#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 /*<<< orphan*/ printf(char *, int);
void finish() {
  char stack[65536];
  int i;
  for (i = 0; i < 65536; i++)
    if (stack[i] != 0x55)
      break;
  printf("Max Stack usage = %d\n", 65536 - i);
}


x86 assembly (clang, -O0):
<finish>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10010,%rsp
movl   $0x0,-0x10004(%rbp)
cmpl   $0x10000,-0x10004(%rbp)
jge    116b <finish+0x5b>
movslq -0x10004(%rbp),%rax
movsbl -0x10000(%rbp,%rax,1),%eax
ff
cmp    $0x55,%eax
je     1152 <finish+0x42>
jmp    116b <finish+0x5b>
jmp    1157 <finish+0x47>
mov    -0x10004(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10004(%rbp)
jmp    1125 <finish+0x15>
mov    $0x10000,%esi
sub    -0x10004(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
add    $0x10010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finish>:
sub    $0xff88,%rsp
mov    $0x10000,%esi
xor    %eax,%eax
test   %al,%al
jne    117b <finish+0x6b>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x55,-0x7f(%rsp,%rax,1)
jne    115d <finish+0x4d>
cmpb   $0x55,-0x7e(%rsp,%rax,1)
jne    1163 <finish+0x53>
cmpb   $0x55,-0x7d(%rsp,%rax,1)
jne    1169 <finish+0x59>
cmp    $0xfffc,%rax
je     1179 <finish+0x69>
lea    0x4(%rax),%rcx
cmpb   $0x55,-0x7c(%rsp,%rax,1)
mov    %rcx,%rax
je     1130 <finish+0x20>
jmp    1170 <finish+0x60>
add    $0x1,%rax
jmp    116d <finish+0x5d>
add    $0x2,%rax
jmp    116d <finish+0x5d>
add    $0x3,%rax
mov    %rax,%rcx
mov    $0x10000,%esi
sub    %ecx,%esi
jmp    117b <finish+0x6b>
xor    %esi,%esi
lea    0xe7e(%rip),%rdi
add    $0xff88,%rsp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Max Stack usage = %d\0A\00"
define void @finish() {
%1 = alloca [65536 x i8]
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %15, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 65536
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 85
br i1 %12, label %13, label %14
13: ; preds = %6
br label %18
14: ; preds = %6
br label %15
15: ; preds = %14
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %3
18: ; preds = %13, %3
%19 = load i32, i32* %2
%20 = sub nsw i32 65536, %19
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %20)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Max Stack usage = %d\0A\00"
define void @finish() {
%1 = alloca [65536 x i8]
%2 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 0
br i1 undef, label %3, label %30
3: ; preds = %0, %22
%4 = phi i64 [ %20, %22 ], [ 0, %0 ]
%5 = or i64 %4, 1
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 85
br i1 %8, label %9, label %26
9: ; preds = %3
%10 = or i64 %4, 2
%11 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 85
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = or i64 %4, 3
%16 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 85
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = add nuw nsw i64 %4, 4
%21 = icmp eq i64 %20, 65536
br i1 %21, label %30, label %22
22: ; preds = %19
%23 = getelementptr inbounds [65536 x i8], [65536 x i8]* %1, i64 0, i64 %20
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 85
br i1 %25, label %3, label %26
26: ; preds = %22, %14, %9, %3
%27 = phi i64 [ %5, %3 ], [ %10, %9 ], [ %15, %14 ], [ %20, %22 ]
%28 = trunc i64 %27 to i32
%29 = sub i32 65536, %28
br label %30
30: ; preds = %19, %0, %26
%31 = phi i32 [ %29, %26 ], [ 65536, %0 ], [ 0, %19 ]
%32 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %31)
ret void
}