#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_6__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  scalar_t__ ss_size;
};
typedef TYPE_1__ stack_t;

/* Variables and functions */
int /*<<< orphan*/ ENOMEM;
scalar_t__ MINSIGSTKSZ;
int __sigaltstack(TYPE_1__ const *, TYPE_1__ *);
int /*<<< orphan*/ errno;
int sigaltstack(const stack_t *__restrict nstack, stack_t *__restrict ostack) {
  if (nstack && nstack->ss_size < MINSIGSTKSZ) {
    errno = ENOMEM;
    return -1;
  }
  return __sigaltstack(nstack, ostack);
}


x86 assembly (clang, -O0):
<sigaltstack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1160 <sigaltstack+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2eaf(%rip),%rcx
cmp    (%rcx),%rax
jge    1160 <sigaltstack+0x50>
mov    0x2e8f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1170 <sigaltstack+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <__sigaltstack@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigaltstack>:
test   %rdi,%rdi
je     113c <sigaltstack+0x2c>
mov    (%rdi),%rax
mov    0x2ec9(%rip),%rcx
cmp    (%rcx),%rax
jge    113c <sigaltstack+0x2c>
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    0x2e9c(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret
jmp    1030 <__sigaltstack@plt>

LLVM IR (-O0):
%struct.TYPE_6__ = type { i64 }
@MINSIGSTKSZ = global i64 0
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @sigaltstack(%struct.TYPE_6__* noalias %0, %struct.TYPE_6__* noalias %1) {
%3 = alloca i32
%4 = alloca %struct.TYPE_6__*
%5 = alloca %struct.TYPE_6__*
store %struct.TYPE_6__* %0, %struct.TYPE_6__** %4
store %struct.TYPE_6__* %1, %struct.TYPE_6__** %5
%6 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%7 = icmp ne %struct.TYPE_6__* %6, null
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @MINSIGSTKSZ
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = load i32, i32* @ENOMEM
store i32 %15, i32* @errno
store i32 -1, i32* %3
br label %20
16: ; preds = %8, %2
%17 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%18 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%19 = call i32 @__sigaltstack(%struct.TYPE_6__* %17, %struct.TYPE_6__* %18)
store i32 %19, i32* %3
br label %20
20: ; preds = %16, %14
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i64 }
@MINSIGSTKSZ = global i64 0
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @sigaltstack(%struct.TYPE_6__* noalias %0, %struct.TYPE_6__* noalias %1) {
%3 = icmp eq %struct.TYPE_6__* %0, null
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @MINSIGSTKSZ
%8 = icmp slt i64 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = load i32, i32* @ENOMEM
store i32 %10, i32* @errno
br label %13
11: ; preds = %4, %2
%12 = tail call i32 @__sigaltstack(%struct.TYPE_6__* %0, %struct.TYPE_6__* %1)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ -1, %9 ], [ %12, %11 ]
ret i32 %14
}