#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 */

/* Type definitions */
struct sigaction {
  int dummy;
};

/* Variables and functions */
int errno;
int syscall(int, int, int, int, int /*<<< orphan*/, int /*<<< orphan*/);
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
  int ret = syscall(98, sig, (int)act, (int)oact, 0, 0);
  if (ret < 0) {
    errno = -ret;
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sigaction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    $0x62,%edi
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1030 <syscall@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1169 <sigaction+0x59>
xor    %ecx,%ecx
sub    -0x1c(%rbp),%ecx
mov    0x2e85(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    116f <sigaction+0x5f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigaction>:
push   %rax
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %edi,%esi
mov    $0x62,%edi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <syscall@plt>
test   %eax,%eax
js     112f <sigaction+0x1f>
pop    %rcx
ret
neg    %eax
mov    0x2ea8(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sigaction = type { i32 }
@errno = global i32 0
define i32 @sigaction(i32 %0, %struct.sigaction* %1, %struct.sigaction* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sigaction*
%7 = alloca %struct.sigaction*
%8 = alloca i32
store i32 %0, i32* %5
store %struct.sigaction* %1, %struct.sigaction** %6
store %struct.sigaction* %2, %struct.sigaction** %7
%9 = load i32, i32* %5
%10 = load %struct.sigaction*, %struct.sigaction** %6
%11 = ptrtoint %struct.sigaction* %10 to i32
%12 = load %struct.sigaction*, %struct.sigaction** %7
%13 = ptrtoint %struct.sigaction* %12 to i32
%14 = call i32 @syscall(i32 98, i32 %9, i32 %11, i32 %13, i32 0, i32 0)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i32, i32* %8
%19 = sub nsw i32 0, %18
store i32 %19, i32* @errno
store i32 -1, i32* %4
br label %22
20: ; preds = %3
%21 = load i32, i32* %8
store i32 %21, i32* %4
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.sigaction = type { i32 }
@errno = global i32 0
define i32 @sigaction(i32 %0, %struct.sigaction* %1, %struct.sigaction* %2) {
%4 = ptrtoint %struct.sigaction* %1 to i64
%5 = trunc i64 %4 to i32
%6 = ptrtoint %struct.sigaction* %2 to i64
%7 = trunc i64 %6 to i32
%8 = tail call i32 @syscall(i32 98, i32 %0, i32 %5, i32 %7, i32 0, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = sub nsw i32 0, %8
store i32 %11, i32* @errno
br label %12
12: ; preds = %3, %10
%13 = phi i32 [ -1, %10 ], [ %8, %3 ]
ret i32 %13
}