#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int ss_size;
  int ss_flags;
  scalar_t__ ss_sp;
};
typedef TYPE_1__ stack_t;

/* Variables and functions */
int SS_DISABLE;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, scalar_t__, unsigned char *, int, char *);
int sigaltstack(int /*<<< orphan*/ *, TYPE_1__ *);
void print_signal_stack() {
  int ret_val;
  stack_t oss;
  ret_val = sigaltstack(NULL, &oss);
  if (ret_val) {
    perror("ERROR, sigaltstack failed");
    exit(1);
  }
  printf("ESP of original stack: %p, top: %p, size: %ld, disabled = %s\n",
         oss.ss_sp, (unsigned char *)oss.ss_sp + oss.ss_size, oss.ss_size,
         (oss.ss_flags & SS_DISABLE) ? "true" : "false");
}


x86 assembly (clang, -O0):
<print_signal_stack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1060 <sigaltstack@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1178 <print_signal_stack+0x38>
lea    0xe97(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
movslq -0x18(%rbp),%rax
add    %rax,%rdx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%edi
mov    0x2e54(%rip),%rax
and    (%rax),%edi
lea    0xec0(%rip),%r8
lea    0xeb4(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%r8
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_signal_stack>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1060 <sigaltstack@plt>
test   %eax,%eax
jne    1194 <print_signal_stack+0x54>
mov    0x10(%rsp),%rsi
movslq 0x8(%rsp),%rcx
mov    %rcx,%rdx
add    %rsi,%rdx
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
and    0xc(%rsp),%eax
lea    0xee5(%rip),%rax
lea    0xed9(%rip),%r8
cmove  %rax,%r8
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
add    $0x18,%rsp
ret
lea    0xe65(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32, i64 }
@.str = [26 x i8] c"ERROR, sigaltstack failed\00"
@.str.1 = [62 x i8] c"ESP of original stack: %p, top: %p, size: %ld, disabled = %s\0A\00"
@SS_DISABLE = global i32 0
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [6 x i8] c"false\00"
define void @print_signal_stack() {
%1 = alloca i32
%2 = alloca %struct.TYPE_3__
%3 = call i32 @sigaltstack(i32* null, %struct.TYPE_3__* %2)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 2
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 2
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to i8*
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 1
%22 = load i32, i32* %21
%23 = load i32, i32* @SS_DISABLE
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%28 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i64 %11, i8* %18, i32 %20, i8* %27)
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32, i64 }
@.str = [26 x i8] c"ERROR, sigaltstack failed\00"
@.str.1 = [62 x i8] c"ESP of original stack: %p, top: %p, size: %ld, disabled = %s\0A\00"
@SS_DISABLE = global i32 0
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [6 x i8] c"false\00"
define void @print_signal_stack() {
%1 = alloca %struct.TYPE_3__
%2 = bitcast %struct.TYPE_3__* %1 to i8*
%3 = call i32 @sigaltstack(i32* null, %struct.TYPE_3__* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 2
%10 = load i64, i64* %9
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%17 = load i32, i32* %16
%18 = load i32, i32* @SS_DISABLE
%19 = and i32 %18, %17
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%22 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i64 %10, i8* %15, i32 %13, i8* %21)
ret void
}