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

/* Variables and functions */
int /*<<< orphan*/ SIGTRAP;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i = 0;
  sigset_t ss;
  struct sigaction sa;
  fprintf(stderr, "ignoring SIGTRAP\n");
  sa.sa_handler = SIG_IGN;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  sigaction(SIGTRAP, &sa, NULL);
  while (1) {
    i++;
    pause();
    fprintf(stderr, "after pause %d\n", i);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x8,%rdi
call   1050 <sigemptyset@plt>
movq   $0x0,-0x28(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <pause@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11ab <main+0x6b>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e88(%rip),%r15
mov    (%r15),%edi
lea    0xea6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <sigemptyset@plt>
movq   $0x0,(%rsp)
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
mov    $0x1,%ebx
lea    0xe73(%rip),%r14
nop
xor    %eax,%eax
call   1060 <pause@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%ebx
jmp    11a0 <main+0x60>

LLVM IR (-O0):
%struct.sigaction = type { i64, i32, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"ignoring SIGTRAP\0A\00"
@SIG_IGN = global i32 0
@SIGTRAP = global i32 0
@.str.1 = [16 x i8] c"after pause %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sigaction
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @SIG_IGN
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %8, i32 0, i32 2
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %8, i32 0, i32 1
%14 = call i32 @sigemptyset(i32* %13)
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %8, i32 0, i32 0
store i64 0, i64* %15
%16 = load i32, i32* @SIGTRAP
%17 = call i32 @sigaction(i32 %16, %struct.sigaction* %8, i32* null)
br label %18
18: ; preds = %2, %18
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
%21 = call i32 (...) @pause()
%22 = load i32, i32* @stderr
%23 = load i32, i32* %6
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %18
}

LLVM IR (-O2):
%struct.sigaction = type { i64, i32, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"ignoring SIGTRAP\0A\00"
@SIG_IGN = global i32 0
@SIGTRAP = global i32 0
@.str.1 = [16 x i8] c"after pause %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @SIG_IGN
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
%10 = call i32 @sigemptyset(i32* %9)
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store i64 0, i64* %11
%12 = load i32, i32* @SIGTRAP
%13 = call i32 @sigaction(i32 %12, %struct.sigaction* %3, i32* null)
br label %14
14: ; preds = %14, %2
%15 = phi i32 [ 0, %2 ], [ %16, %14 ]
%16 = add nuw nsw i32 %15, 1
%17 = call i32 (...) @pause()
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %14
}