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

/* Variables and functions */
int SA_NODEFER;
int SA_RESETHAND;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             struct sigaction *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  struct sigaction act, oldact;
  sigaddset(&act.sa_mask, SIGQUIT);
  act.sa_flags = SA_RESETHAND | SA_NODEFER;
  sigaction(SIGINT, &act, &oldact);
  while (1) {
    sleep(1);
    write(1, "sleeping", 1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1060 <sigaddset@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    0x2e53(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <sigaction@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    $0x1,%edx
lea    0xe5a(%rip),%rsi
mov    %edx,%edi
call   1040 <write@plt>
jmp    1190 <main+0x50>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x4(%rsp),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
call   1060 <sigaddset@plt>
mov    0x2e81(%rip),%rax
mov    0x2e62(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,(%rsp)
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
call   1030 <sigaction@plt>
lea    0xe76(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
jmp    1190 <main+0x50>

LLVM IR (-O0):
%struct.sigaction = type { i32, i32 }
@SIGQUIT = global i32 0
@SA_RESETHAND = global i32 0
@SA_NODEFER = global i32 0
@SIGINT = global i32 0
@.str = [9 x i8] c"sleeping\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sigaction
%3 = alloca %struct.sigaction
store i32 0, i32* %1
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 1
%5 = load i32, i32* @SIGQUIT
%6 = call i32 @sigaddset(i32* %4, i32 %5)
%7 = load i32, i32* @SA_RESETHAND
%8 = load i32, i32* @SA_NODEFER
%9 = or i32 %7, %8
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @SIGINT
%12 = call i32 @sigaction(i32 %11, %struct.sigaction* %2, %struct.sigaction* %3)
br label %13
13: ; preds = %0, %13
%14 = call i32 @sleep(i32 1)
%15 = call i32 @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1)
br label %13
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32 }
@SIGQUIT = global i32 0
@SA_RESETHAND = global i32 0
@SA_NODEFER = global i32 0
@SIGINT = global i32 0
@.str = [9 x i8] c"sleeping\00"
define i32 @main() {
%1 = alloca %struct.sigaction
%2 = alloca %struct.sigaction
%3 = bitcast %struct.sigaction* %1 to i8*
%4 = bitcast %struct.sigaction* %2 to i8*
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
%6 = load i32, i32* @SIGQUIT
%7 = call i32 @sigaddset(i32* %5, i32 %6)
%8 = load i32, i32* @SA_RESETHAND
%9 = load i32, i32* @SA_NODEFER
%10 = or i32 %9, %8
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* @SIGINT
%13 = call i32 @sigaction(i32 %12, %struct.sigaction* %1, %struct.sigaction* %2)
br label %14
14: ; preds = %14, %0
%15 = call i32 @sleep(i32 1)
%16 = call i32 @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1)
br label %14
}