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

/* Variables and functions */
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ exit(int);
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*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int main(void) {
  void sigint_handler(int sig);
  char s[200];
  struct sigaction sa;
  sa.sa_handler = sigint_handler;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  if (sigaction(SIGINT, &sa, NULL) == -1) {
    perror("sigaction");
    exit(1);
  }
  printf("Enter a string:\n");
  if (fgets(s, sizeof s, stdin) == NULL)
    perror("fgets");
  else
    printf("You entered: %s\n", s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e57(%rip),%rax
mov    %rax,-0xe8(%rbp)
movq   $0x0,-0xd8(%rbp)
lea    -0xe8(%rbp),%rdi
add    $0x8,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    -0xe8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    11d3 <main+0x73>
lea    0xe3c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xd0(%rbp),%rdi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
mov    $0xc8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1216 <main+0xb6>
lea    0xe0f(%rip),%rdi
call   1070 <perror@plt>
jmp    122b <main+0xcb>
lea    -0xd0(%rbp),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0xe8,%rsp
mov    0x2e52(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
cmp    $0xffffffff,%eax
je     1204 <main+0x94>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rdi
mov    $0xc8,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11f6 <main+0x86>
lea    0xe30(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xe8,%rsp
ret
lea    0xe0d(%rip),%rdi
call   1080 <perror@plt>
jmp    11ec <main+0x7c>
lea    0xdf5(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32, i64 }
@SIGINT = global i32 0
@.str = [10 x i8] c"sigaction\00"
@.str.1 = [17 x i8] c"Enter a string:\0A\00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"fgets\00"
@.str.3 = [17 x i8] c"You entered: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [200 x i8]
%3 = alloca %struct.sigaction
store i32 0, i32* %1
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 0
store void (i32)* @sigint_handler, void (i32)** %4
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 2
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 1
%7 = call i32 @sigemptyset(i32* %6)
%8 = load i32, i32* @SIGINT
%9 = call i32 @sigaction(i32 %8, %struct.sigaction* %3, i32* null)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%17 = load i32, i32* @stdin
%18 = call i32* @fgets(i8* %16, i32 200, i32 %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %25
22: ; preds = %14
%23 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %20
ret i32 0
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32, i64 }
@SIGINT = global i32 0
@.str = [10 x i8] c"sigaction\00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"fgets\00"
@.str.3 = [17 x i8] c"You entered: %s\0A\00"
@str = [16 x i8] c"Enter a string:\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = alloca %struct.sigaction
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.sigaction* %2 to i8*
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 0
store void (i32)* @sigint_handler, void (i32)** %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 2
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 1
%8 = call i32 @sigemptyset(i32* %7)
%9 = load i32, i32* @SIGINT
%10 = call i32 @sigaction(i32 %9, %struct.sigaction* %2, i32* null)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%17 = load i32, i32* @stdin
%18 = call i32* @fgets(i8* %3, i32 200, i32 %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %24
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %24
24: ; preds = %22, %20
ret i32 0
}