#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 *);
void check_stack_growth(const int *second) {
  int first;
  if (!second)
    check_stack_growth(&first);
  else if (second < &first)
    printf("Stack grows upward\n");
  else
    printf("Stack grows downward\n");
}


x86 assembly (clang, -O0):
<check_stack_growth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1145 <check_stack_growth+0x25>
lea    -0xc(%rbp),%rdi
call   1040 <check_stack_growth@plt>
jmp    1175 <check_stack_growth+0x55>
lea    -0xc(%rbp),%rax
cmp    %rax,-0x8(%rbp)
jae    1164 <check_stack_growth+0x44>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
jmp    1170 <check_stack_growth+0x50>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
jmp    1175 <check_stack_growth+0x55>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_stack_growth>:
push   %rax
mov    %rsp,%rax
test   %rdi,%rdi
je     1127 <check_stack_growth+0x17>
cmp    %rdi,%rax
jbe    1143 <check_stack_growth+0x33>
lea    0xef0(%rip),%rdi
jmp    114a <check_stack_growth+0x3a>
lea    0x4(%rsp),%rcx
cmp    %rax,%rcx
lea    0xedf(%rip),%rax
lea    0xec3(%rip),%rdi
cmova  %rax,%rdi
jmp    114a <check_stack_growth+0x3a>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Stack grows upward\0A\00"
@.str.1 = [22 x i8] c"Stack grows downward\0A\00"
define void @check_stack_growth(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = icmp ne i32* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
br label %15
7: ; preds = %1
%8 = load i32*, i32** %2
%9 = icmp ult i32* %8, %3
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %14
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
br label %15
15: ; preds = %14, %6
ret void
}

LLVM IR (-O2):
@str = [21 x i8] c"Stack grows downward\00"
@str.2 = [19 x i8] c"Stack grows upward\00"
define void @check_stack_growth(i32* readnone %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32* %0, null
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = bitcast i32* %2 to i8*
%8 = icmp ugt i32* %2, %3
%9 = select i1 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0)
%10 = call i32 @puts(i8* dereferenceable(1) %9)
br label %17
11: ; preds = %1
%12 = icmp ugt i32* %3, %0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0))
br label %17
15: ; preds = %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %13, %15, %6
ret void
}