#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;
  int /*<<< orphan*/ ss_size;
  void *ss_sp;
};
typedef TYPE_1__ stack_t;

/* Variables and functions */
int /*<<< orphan*/ SIGSTKSZ;
scalar_t__ SS_ONSTACK;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ perror(char *);
scalar_t__ sigaltstack(TYPE_1__ *, int /*<<< orphan*/ *);
void hipe_sigaltstack(void *ss_sp) {
  stack_t ss;
  ss.ss_sp = ss_sp;
  ss.ss_flags = SS_ONSTACK;
  ss.ss_size = SIGSTKSZ;
  if (sigaltstack(&ss, NULL) < 0) {
    ss.ss_flags = 0;
    if (sigaltstack(&ss, NULL) < 0) {
      perror("sigaltstack");
      abort();
    }
  }
}


x86 assembly (clang, -O0):
<hipe_sigaltstack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <sigaltstack@plt>
cmp    $0x0,%rax
jge    11ac <hipe_sigaltstack+0x7c>
movq   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <sigaltstack@plt>
cmp    $0x0,%rax
jge    11a7 <hipe_sigaltstack+0x77>
lea    0xe65(%rip),%rdi
call   1040 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11ac <hipe_sigaltstack+0x7c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hipe_sigaltstack>:
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
mov    0x2ea8(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <sigaltstack@plt>
test   %rax,%rax
jns    117a <hipe_sigaltstack+0x4a>
movq   $0x0,(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <sigaltstack@plt>
test   %rax,%rax
js     117f <hipe_sigaltstack+0x4f>
add    $0x18,%rsp
ret
lea    0xe7a(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i32, i8* }
@SS_ONSTACK = global i64 0
@SIGSTKSZ = global i32 0
@.str = [12 x i8] c"sigaltstack\00"
define void @hipe_sigaltstack(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.TYPE_3__
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 2
store i8* %4, i8** %5
%6 = load i64, i64* @SS_ONSTACK
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 0
store i64 %6, i64* %7
%8 = load i32, i32* @SIGSTKSZ
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 1
store i32 %8, i32* %9
%10 = call i64 @sigaltstack(%struct.TYPE_3__* %3, i32* null)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 0
store i64 0, i64* %13
%14 = call i64 @sigaltstack(%struct.TYPE_3__* %3, i32* null)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %12
br label %20
20: ; preds = %19, %1
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i32, i8* }
@SS_ONSTACK = global i64 0
@SIGSTKSZ = global i32 0
@.str = [12 x i8] c"sigaltstack\00"
define void @hipe_sigaltstack(i8* %0) {
%2 = alloca %struct.TYPE_3__
%3 = bitcast %struct.TYPE_3__* %2 to i8*
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 2
store i8* %0, i8** %4
%5 = load i64, i64* @SS_ONSTACK
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
store i64 %5, i64* %6
%7 = load i32, i32* @SIGSTKSZ
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 1
store i32 %7, i32* %8
%9 = call i64 @sigaltstack(%struct.TYPE_3__* %2, i32* null)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %1
store i64 0, i64* %6
%12 = call i64 @sigaltstack(%struct.TYPE_3__* %2, i32* null)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @abort()
unreachable
17: ; preds = %11, %1
ret void
}