#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;
  int ss_flags;
};
typedef TYPE_1__ stack_t;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOMEM;
scalar_t__ MINSIGSTKSZ;
int SS_DISABLE;
int /*<<< orphan*/ errno;
int syscall(int, TYPE_1__ const *, TYPE_1__ *);
int sigaltstack(const stack_t *restrict ss, stack_t *restrict old) {
  if (ss) {
    if (ss->ss_size < MINSIGSTKSZ) {
      errno = ENOMEM;
      return -1;
    }
    if (ss->ss_flags & ~SS_DISABLE) {
      errno = EINVAL;
      return -1;
    }
  }
  return syscall(186, ss, old);
}


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     11a1 <sigaltstack+0x91>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2eaf(%rip),%rcx
cmp    (%rcx),%rax
jge    1160 <sigaltstack+0x50>
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
mov    0x2e76(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <sigaltstack+0xa6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2e72(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     119c <sigaltstack+0x8c>
mov    0x2e3b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3a(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <sigaltstack+0xa6>
jmp    11a1 <sigaltstack+0x91>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0xba,%edi
call   1030 <syscall@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigaltstack>:
mov    %rsi,%rdx
mov    %rdi,%rsi
test   %rdi,%rdi
je     115b <sigaltstack+0x4b>
mov    (%rsi),%rax
mov    0x2ec3(%rip),%rcx
cmp    (%rcx),%rax
jge    1133 <sigaltstack+0x23>
mov    0x2e9f(%rip),%rax
jmp    114a <sigaltstack+0x3a>
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
not    %eax
test   %eax,0x8(%rsi)
je     115b <sigaltstack+0x4b>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    0x2e75(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret
mov    $0xba,%edi
jmp    1030 <syscall@plt>

LLVM IR (-O0):
%struct.TYPE_6__ = type { i64, i32 }
@MINSIGSTKSZ = global i64 0
@ENOMEM = global i32 0
@errno = global i32 0
@SS_DISABLE = global i32 0
@EINVAL = 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 %27
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 %31
16: ; preds = %8
%17 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%18 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load i32, i32* @SS_DISABLE
%21 = xor i32 %20, -1
%22 = and i32 %19, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = load i32, i32* @EINVAL
store i32 %25, i32* @errno
store i32 -1, i32* %3
br label %31
26: ; preds = %16
br label %27
27: ; preds = %26, %2
%28 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%29 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%30 = call i32 @syscall(i32 186, %struct.TYPE_6__* %28, %struct.TYPE_6__* %29)
store i32 %30, i32* %3
br label %31
31: ; preds = %27, %24, %14
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i64, i32 }
@MINSIGSTKSZ = global i64 0
@ENOMEM = global i32 0
@errno = global i32 0
@SS_DISABLE = global i32 0
@EINVAL = 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 %20, 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 %22
11: ; preds = %4
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 1
%13 = load i32, i32* %12
%14 = load i32, i32* @SS_DISABLE
%15 = xor i32 %14, -1
%16 = and i32 %13, %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = load i32, i32* @EINVAL
store i32 %19, i32* @errno
br label %22
20: ; preds = %11, %2
%21 = tail call i32 @syscall(i32 186, %struct.TYPE_6__* %0, %struct.TYPE_6__* %1)
br label %22
22: ; preds = %20, %18, %9
%23 = phi i32 [ -1, %9 ], [ -1, %18 ], [ %21, %20 ]
ret i32 %23
}