#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
#define SIGCHLD 130
#define SIGTRAP 129
#define SIGWINCH 128
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getuid();
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int is_fatal_sig(int sig) {
  char buf[512];
  FILE *f;
  switch (sig) {
  case SIGTRAP:
  case SIGWINCH:
  case SIGCHLD:
    return 0;
  default:
    snprintf(buf, 512, "/tmp/fatal_sig_UID%u", getuid());
    f = fopen(buf, "w");
    if (f) {
      fprintf(f, "Received fatal signal %d\n", sig);
      fclose(f);
    }
    return 1;
  }
}


x86 assembly (clang, -O0):
<is_fatal_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x2,%eax
ja     117e <is_fatal_sig+0x2e>
jmp    1172 <is_fatal_sig+0x22>
movl   $0x0,-0x4(%rbp)
jmp    11fe <is_fatal_sig+0xae>
lea    -0x210(%rbp),%rax
mov    %rax,-0x220(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    -0x220(%rbp),%rdi
mov    %eax,%ecx
mov    $0x200,%esi
lea    0xe58(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x210(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
je     11f7 <is_fatal_sig+0xa7>
mov    -0x218(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe31(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_fatal_sig>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %edi,%r14d
lea    -0x80(%r14),%eax
xor    %ebp,%ebp
cmp    $0x3,%eax
jb     11bf <is_fatal_sig+0x6f>
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xe89(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %eax,%ecx
call   1050 <snprintf@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11bf <is_fatal_sig+0x6f>
mov    %rax,%rbx
lea    0xe6b(%rip),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/tmp/fatal_sig_UID%u\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [26 x i8] c"Received fatal signal %d\0A\00"
define i32 @is_fatal_sig(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = alloca i32*
store i32 %0, i32* %3
%6 = load i32, i32* %3
switch i32 %6, label %8 [
i32 129, label %7
i32 128, label %7
i32 130, label %7
]
7: ; preds = %1, %1, %1
store i32 0, i32* %2
br label %23
8: ; preds = %1
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = call i32 (...) @getuid()
%11 = call i32 @snprintf(i8* %9, i32 512, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %8
%17 = load i32*, i32** %5
%18 = load i32, i32* %3
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %5
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %16, %8
store i32 1, i32* %2
br label %23
23: ; preds = %22, %7
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [21 x i8] c"/tmp/fatal_sig_UID%u\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [26 x i8] c"Received fatal signal %d\0A\00"
define i32 @is_fatal_sig(i32 %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = add i32 %0, -128
%5 = icmp ult i32 %4, 3
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = tail call i32 (...) @getuid()
%8 = call i32 @snprintf(i8* %3, i32 512, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%13 = call i32 @fclose(i32* %9)
br label %14
14: ; preds = %6, %11, %1
%15 = phi i32 [ 0, %1 ], [ 1, %11 ], [ 1, %6 ]
ret i32 %15
}