#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 */
void *alloca(int);
int /*<<< orphan*/ memset(void *, int, int);
int /*<<< orphan*/ printf(char *, void *, short, void *, short);
int main() {
  void *bottom = alloca(4);
  void *top = alloca(4);
  if (bottom < top) {
    memset(bottom, 1, top - bottom);
  } else {
    memset(top, 1, bottom - top);
  }
  printf("%p %x\n%p %x\n", bottom, *(short *)bottom, top, *(short *)top);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1050 <alloca@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1050 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1189 <main+0x59>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    $0x1,%esi
call   1040 <memset@plt>
jmp    11a4 <main+0x74>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    $0x1,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%dx
mov    -0x18(%rbp),%rcx
mov    -0x18(%rbp),%rax
lea    0xe42(%rip),%rdi
movswl %dx,%edx
movswl (%rax),%r8d
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1050 <alloca@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1050 <alloca@plt>
mov    %rax,%rbx
cmp    %rax,%r14
mov    %rax,%rdi
cmovb  %r14,%rdi
mov    %ebx,%edx
cmovae %r14d,%edx
sub    %edi,%edx
mov    $0x1,%esi
call   1040 <memset@plt>
movswl (%r14),%edx
movswl (%rbx),%r8d
lea    0xe87(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%p %x\0A%p %x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @alloca(i32 4)
store i8* %4, i8** %2
%5 = call i8* @alloca(i32 4)
store i8* %5, i8** %3
%6 = load i8*, i8** %2
%7 = load i8*, i8** %3
%8 = icmp ult i8* %6, %7
br i1 %8, label %9, label %18
9: ; preds = %0
%10 = load i8*, i8** %2
%11 = load i8*, i8** %3
%12 = load i8*, i8** %2
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint i8* %12 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = call i32 @memset(i8* %10, i32 1, i32 %16)
br label %27
18: ; preds = %0
%19 = load i8*, i8** %3
%20 = load i8*, i8** %2
%21 = load i8*, i8** %3
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
%26 = call i32 @memset(i8* %19, i32 1, i32 %25)
br label %27
27: ; preds = %18, %9
%28 = load i8*, i8** %2
%29 = load i8*, i8** %2
%30 = bitcast i8* %29 to i16*
%31 = load i16, i16* %30
%32 = load i8*, i8** %3
%33 = load i8*, i8** %3
%34 = bitcast i8* %33 to i16*
%35 = load i16, i16* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %28, i16 signext %31, i8* %32, i16 signext %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"%p %x\0A%p %x\0A\00"
define i32 @main() {
%1 = tail call i8* @alloca(i32 4)
%2 = tail call i8* @alloca(i32 4)
%3 = icmp ult i8* %1, %2
%4 = select i1 %3, i8* %2, i8* %1
%5 = select i1 %3, i8* %1, i8* %2
%6 = ptrtoint i8* %4 to i64
%7 = ptrtoint i8* %5 to i64
%8 = sub i64 %6, %7
%9 = trunc i64 %8 to i32
%10 = tail call i32 @memset(i8* %5, i32 1, i32 %9)
%11 = bitcast i8* %1 to i16*
%12 = load i16, i16* %11
%13 = bitcast i8* %2 to i16*
%14 = load i16, i16* %13
%15 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %1, i16 signext %12, i8* %2, i16 signext %14)
ret i32 0
}