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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int SA_RESETHAND;
int SA_RESTART;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sigaction(int /*<<< orphan*/, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  void sigint_handler(int sig);
  struct sigaction handler;
  sigset_t block_sigs;
  char input[100];
  handler.sa_handler = sigint_handler;
  handler.sa_flags = SA_RESETHAND | SA_RESTART;
  sigemptyset(&block_sigs);
  sigaddset(&block_sigs, SIGQUIT);
  handler.sa_mask = block_sigs;
  if (sigaction(SIGINT, &handler, NULL) == -1) {
    perror("sigaction() failed");
    exit(EXIT_FAILURE);
  } else {
    while (1) {
      printf("\nType something: ");
      fgets(input, 100, stdin);
      printf("You type: %s", input);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e20(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    0x2e44(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
lea    -0x24(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    1203 <main+0x93>
lea    0xe10(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1208 <main+0x98>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x90(%rbp),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1208 <main+0x98>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2e2b(%rip),%rax
mov    %rax,0x10(%rsp)
mov    0x2e47(%rip),%rax
mov    0x2e50(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x18(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <sigaddset@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
je     122a <main+0xba>
lea    0xe2c(%rip),%r14
mov    0x2de2(%rip),%r12
lea    0x20(%rsp),%rbx
lea    0xe2b(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1200 <main+0x90>
lea    0xdcf(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32, i32 }
@SA_RESETHAND = global i32 0
@SA_RESTART = global i32 0
@SIGQUIT = global i32 0
@SIGINT = global i32 0
@.str = [19 x i8] c"sigaction() failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"\0AType something: \00"
@stdin = global i32 0
@.str.2 = [13 x i8] c"You type: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sigaction
%7 = alloca i32
%8 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
store void (i32)* @sigint_handler, void (i32)** %9
%10 = load i32, i32* @SA_RESETHAND
%11 = load i32, i32* @SA_RESTART
%12 = or i32 %10, %11
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 1
store i32 %12, i32* %13
%14 = call i32 @sigemptyset(i32* %7)
%15 = load i32, i32* @SIGQUIT
%16 = call i32 @sigaddset(i32* %7, i32 %15)
%17 = load i32, i32* %7
%18 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* @SIGINT
%20 = call i32 @sigaction(i32 %19, %struct.sigaction* %6, i32* null)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %2
br label %27
27: ; preds = %26, %27
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %29, i32 100, i32 %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %27
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32, i32 }
@SA_RESETHAND = global i32 0
@SA_RESTART = global i32 0
@SIGQUIT = global i32 0
@SIGINT = global i32 0
@.str = [19 x i8] c"sigaction() failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"\0AType something: \00"
@stdin = global i32 0
@.str.2 = [13 x i8] c"You type: %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sigaction
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = bitcast %struct.sigaction* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store void (i32)* @sigint_handler, void (i32)** %9
%10 = load i32, i32* @SA_RESETHAND
%11 = load i32, i32* @SA_RESTART
%12 = or i32 %11, %10
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = call i32 @sigemptyset(i32* %4)
%15 = load i32, i32* @SIGQUIT
%16 = call i32 @sigaddset(i32* %4, i32 %15)
%17 = load i32, i32* %4
%18 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* @SIGINT
%20 = call i32 @sigaction(i32 %19, %struct.sigaction* %3, i32* null)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %2, %26
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %8, i32 100, i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %26
}