#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 SA_RESETHAND;
int SA_RESTART;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, 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() {
  struct sigaction newhander;
  sigset_t blocked;
  void inthander(int);
  char x[100];
  newhander.sa_handler = inthander;
  newhander.sa_flags = SA_RESETHAND | SA_RESTART;
  sigemptyset(&blocked);
  sigaddset(&blocked, SIGQUIT);
  newhander.sa_mask = blocked;
  if (sigaction(SIGINT, &newhander, NULL) == -1)
    perror("sigaction error");
  else
    while (1) {
      fgets(x, 100, stdin);
      printf("input %s\n", x);
    }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    0x2e5b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
lea    -0x1c(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    11e3 <main+0x83>
lea    0xe27(%rip),%rdi
call   1070 <perror@plt>
jmp    1214 <main+0xb4>
jmp    11e8 <main+0x88>
lea    -0x80(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x80(%rbp),%rsi
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
jmp    11e8 <main+0x88>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    0x2e45(%rip),%rax
mov    %rax,0x10(%rsp)
mov    0x2e59(%rip),%rax
mov    0x2e62(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x18(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigaddset@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
je     120d <main+0xad>
mov    0x2dfb(%rip),%r15
lea    0x20(%rsp),%rbx
lea    0xe2f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    11f0 <main+0x90>
lea    0xdec(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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 = [16 x i8] c"sigaction error\00"
@stdin = global i32 0
@.str.1 = [10 x i8] c"input %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sigaction
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 0
store void (i32)* @inthander, void (i32)** %5
%6 = load i32, i32* @SA_RESETHAND
%7 = load i32, i32* @SA_RESTART
%8 = or i32 %6, %7
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 1
store i32 %8, i32* %9
%10 = call i32 @sigemptyset(i32* %3)
%11 = load i32, i32* @SIGQUIT
%12 = call i32 @sigaddset(i32* %3, i32 %11)
%13 = load i32, i32* %3
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @SIGINT
%16 = call i32 @sigaction(i32 %15, %struct.sigaction* %2, i32* null)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %27
20: ; preds = %0
br label %21
21: ; preds = %20, %21
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %22, i32 100, i32 %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %21
27: ; preds = %18
ret i32 0
}

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 = [16 x i8] c"sigaction error\00"
@stdin = global i32 0
@.str.1 = [10 x i8] c"input %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sigaction
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = bitcast %struct.sigaction* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 0
store void (i32)* @inthander, void (i32)** %7
%8 = load i32, i32* @SA_RESETHAND
%9 = load i32, i32* @SA_RESTART
%10 = or i32 %9, %8
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = call i32 @sigemptyset(i32* %2)
%13 = load i32, i32* @SIGQUIT
%14 = call i32 @sigaddset(i32* %2, i32 %13)
%15 = load i32, i32* %2
%16 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* @SIGINT
%18 = call i32 @sigaction(i32 %17, %struct.sigaction* %1, i32* null)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
ret i32 0
22: ; preds = %0, %22
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %6, i32 100, i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %22
}