#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 {
  void *sa_handler;
  scalar_t__ sa_flags;
  int /*<<< orphan*/ sa_mask;
};

/* Variables and functions */
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sigaction(int, struct sigaction *, struct sigaction *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void *arm_signal(int sig, void *action) {
  struct sigaction nact, oact;
  memset(&nact, 0, sizeof(struct sigaction));
  sigemptyset(&nact.sa_mask);
  nact.sa_handler = action;
  nact.sa_flags = 0;
  sigaction(sig, &nact, &oact);
  return (void *)oact.sa_handler;
}


x86 assembly (clang, -O0):
<arm_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
lea    -0x28(%rbp),%rdi
add    $0x10,%rdi
call   1050 <sigemptyset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1030 <sigaction@plt>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arm_signal>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
lea    0x10(%rsp),%rdi
call   1050 <sigemptyset@plt>
mov    %rbx,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x18(%rsp),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <sigaction@plt>
mov    0x18(%rsp),%rax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i8*, i64, i32 }
define i8* @arm_signal(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sigaction
%6 = alloca %struct.sigaction
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = call i32 @memset(%struct.sigaction* %5, i32 0, i32 24)
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
%9 = call i32 @sigemptyset(i32* %8)
%10 = load i8*, i8** %4
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store i8* %10, i8** %11
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
store i64 0, i64* %12
%13 = load i32, i32* %3
%14 = call i32 @sigaction(i32 %13, %struct.sigaction* %5, %struct.sigaction* %6)
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%16 = load i8*, i8** %15
ret i8* %16
}

LLVM IR (-O2):
%struct.sigaction = type { i8*, i64, i32 }
define i8* @arm_signal(i32 %0, i8* %1) {
%3 = alloca %struct.sigaction
%4 = alloca %struct.sigaction
%5 = bitcast %struct.sigaction* %3 to i8*
%6 = bitcast %struct.sigaction* %4 to i8*
%7 = call i32 @memset(%struct.sigaction* %3, i32 0, i32 24)
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
%9 = call i32 @sigemptyset(i32* %8)
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store i8* %1, i8** %10
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i64 0, i64* %11
%12 = call i32 @sigaction(i32 %0, %struct.sigaction* %3, %struct.sigaction* %4)
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 0
%14 = load i8*, i8** %13
ret i8* %14
}