#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__ {
  scalar_t__ ss_flags;
};
typedef TYPE_1__ stack_t;

/* Variables and functions */
scalar_t__ SS_ONSTACK;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sigaltstack(int /*<<< orphan*/ *, TYPE_1__ *);
void handler() {
  stack_t handler_s;
  if (sigaltstack(NULL, &handler_s) == -1) {
    perror("Unexpected error while attempting to setup test pre-conditions");
    exit(2);
  }
  if (handler_s.ss_flags != SS_ONSTACK) {
    printf("Test FAILED: The alternate stack's ss_flags member does not "
           "contain SS_ONSTACK even though the handler is executing on the "
           "alternate stack\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
call   1060 <sigaltstack@plt>
cmp    $0xffffffff,%eax
jne    1174 <handler+0x34>
lea    0xe9b(%rip),%rdi
call   1040 <perror@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
je     119e <handler+0x5e>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
push   %rax
mov    %rsp,%rsi
xor    %edi,%edi
call   1060 <sigaltstack@plt>
cmp    $0xffffffff,%eax
je     1162 <handler+0x22>
mov    (%rsp),%rax
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%rax
jne    1178 <handler+0x38>
pop    %rax
ret
lea    0xe97(%rip),%rdi
call   1040 <perror@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64 }
@.str = [63 x i8] c"Unexpected error while attempting to setup test pre-conditions\00"
@SS_ONSTACK = global i64 0
@.str.1 = [140 x i8] c"Test FAILED: The alternate stack's ss_flags member does not contain SS_ONSTACK even though the handler is executing on the alternate stack\0A\00"
define void @handler() {
%1 = alloca %struct.TYPE_3__
%2 = call i32 @sigaltstack(i32* null, %struct.TYPE_3__* %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = call i32 @perror(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @exit(i32 2)
unreachable
7: ; preds = %0
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load i64, i64* @SS_ONSTACK
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %7
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64 }
@.str = [63 x i8] c"Unexpected error while attempting to setup test pre-conditions\00"
@SS_ONSTACK = global i64 0
@str = [139 x i8] c"Test FAILED: The alternate stack's ss_flags member does not contain SS_ONSTACK even though the handler is executing on the alternate stack\00"
define void @handler() {
%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, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 2)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @SS_ONSTACK
%12 = icmp eq i64 %10, %11
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([139 x i8], [139 x i8]* @str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %8
ret void
}