#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int si_code;
  int /*<<< orphan*/ si_addr;
};
typedef TYPE_1__ siginfo_t;
typedef int /*<<< orphan*/ pointers;

/* Variables and functions */
#define FPE_FLTDIV 135
#define FPE_FLTINV 134
#define FPE_FLTOVF 133
#define FPE_FLTRES 132
#define FPE_FLTSUB 131
#define FPE_FLTUND 130
#define FPE_INTDIV 129
#define FPE_INTOVF 128
int /*<<< orphan*/ abort();
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ log_err(char *, ...);
void fpe(int sig, siginfo_t *info, void *data) {
  int i;
  int frame_count = 0;
  void *pointers[256];
  switch (info->si_code) {
  case FPE_INTDIV:
    log_err("FPE: integer divide by zero");
    break;
  case FPE_INTOVF:
    log_err("FPE: integer overflow");
    break;
  case FPE_FLTDIV:
    log_err("FPE: floating point divide by zero");
    break;
  case FPE_FLTOVF:
    log_err("FPE: floating point overflow");
    break;
  case FPE_FLTUND:
    log_err("FPE: floating point underflow");
    break;
  case FPE_FLTRES:
    log_err("FPE: floating point inexact result");
    break;
  case FPE_FLTINV:
    log_err("FPE: floating point invalid operation");
    break;
  case FPE_FLTSUB:
    log_err("FPE: floating point sudirript out of range");
    break;
  default:
    log_err("FPE at address %p\n", info->si_addr);
    break;
  }
  frame_count = backtrace(pointers, sizeof(pointers));
  char **frames = backtrace_symbols(pointers, frame_count);
  for (i = 0; i < frame_count; ++i) {
    log_err("frame(%03d): %s", i, frames[i]);
  }
  abort();
}


x86 assembly (clang, -O0):
<fpe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x830(%rbp)
sub    $0x7,%eax
ja     1227 <fpe+0xe7>
mov    -0x830(%rbp),%rax
lea    0xe7a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    123c <fpe+0xfc>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    123c <fpe+0xfc>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    123c <fpe+0xfc>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    123c <fpe+0xfc>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    123c <fpe+0xfc>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    123c <fpe+0xfc>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    123c <fpe+0xfc>
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    123c <fpe+0xfc>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xeef(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
lea    -0x820(%rbp),%rdi
mov    $0x800,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x20(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x828(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12a7 <fpe+0x167>
mov    -0x1c(%rbp),%esi
mov    -0x828(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    126d <fpe+0x12d>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<fpe>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    (%rsi),%eax
add    $0xffffff80,%eax
cmp    $0x7,%eax
ja     1171 <fpe+0x31>
lea    0xea1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xecd(%rip),%rdi
jmp    11c1 <fpe+0x81>
mov    0x4(%rsi),%esi
lea    0xfa9(%rip),%rdi
xor    %eax,%eax
call   1060 <log_err@plt>
jmp    11c8 <fpe+0x88>
lea    0xe95(%rip),%rdi
jmp    11c1 <fpe+0x81>
lea    0xefe(%rip),%rdi
jmp    11c1 <fpe+0x81>
lea    0xf5c(%rip),%rdi
jmp    11c1 <fpe+0x81>
lea    0xf0a(%rip),%rdi
jmp    11c1 <fpe+0x81>
lea    0xec6(%rip),%rdi
jmp    11c1 <fpe+0x81>
lea    0xf1b(%rip),%rdi
jmp    11c1 <fpe+0x81>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1060 <log_err@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x800,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
test   %ebx,%ebx
jle    1219 <fpe+0xd9>
mov    %rax,%r15
mov    %ebx,%r12d
lea    0xf42(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <log_err@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1200 <fpe+0xc0>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [28 x i8] c"FPE: integer divide by zero\00"
@.str.1 = [22 x i8] c"FPE: integer overflow\00"
@.str.2 = [35 x i8] c"FPE: floating point divide by zero\00"
@.str.3 = [29 x i8] c"FPE: floating point overflow\00"
@.str.4 = [30 x i8] c"FPE: floating point underflow\00"
@.str.5 = [35 x i8] c"FPE: floating point inexact result\00"
@.str.6 = [38 x i8] c"FPE: floating point invalid operation\00"
@.str.7 = [43 x i8] c"FPE: floating point sudirript out of range\00"
@.str.8 = [19 x i8] c"FPE at address %p\0A\00"
@.str.9 = [16 x i8] c"frame(%03d): %s\00"
define void @fpe(i32 %0, %struct.TYPE_3__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8*]
%10 = alloca i8**
store i32 %0, i32* %4
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %5
store i8* %2, i8** %6
store i32 0, i32* %8
%11 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%13 = load i32, i32* %12
switch i32 %13, label %30 [
i32 129, label %14
i32 128, label %16
i32 135, label %18
i32 133, label %20
i32 130, label %22
i32 132, label %24
i32 134, label %26
i32 131, label %28
]
14: ; preds = %3
%15 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %35
16: ; preds = %3
%17 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %35
18: ; preds = %3
%19 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %35
20: ; preds = %3
%21 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %35
22: ; preds = %3
%23 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %35
24: ; preds = %3
%25 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %35
26: ; preds = %3
%27 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
br label %35
28: ; preds = %3
%29 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0))
br label %35
30: ; preds = %3
%31 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %30, %28, %26, %24, %22, %20, %18, %16, %14
%36 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 0
%37 = call i32 @backtrace(i8** %36, i32 2048)
store i32 %37, i32* %8
%38 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 0
%39 = load i32, i32* %8
%40 = call i8** @backtrace_symbols(i8** %38, i32 %39)
store i8** %40, i8*** %10
store i32 0, i32* %7
br label %41
41: ; preds = %53, %35
%42 = load i32, i32* %7
%43 = load i32, i32* %8
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %56
45: ; preds = %41
%46 = load i32, i32* %7
%47 = load i8**, i8*** %10
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %46, i8* %51)
br label %53
53: ; preds = %45
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %41
56: ; preds = %41
%57 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [28 x i8] c"FPE: integer divide by zero\00"
@.str.1 = [22 x i8] c"FPE: integer overflow\00"
@.str.2 = [35 x i8] c"FPE: floating point divide by zero\00"
@.str.3 = [29 x i8] c"FPE: floating point overflow\00"
@.str.4 = [30 x i8] c"FPE: floating point underflow\00"
@.str.5 = [35 x i8] c"FPE: floating point inexact result\00"
@.str.6 = [38 x i8] c"FPE: floating point invalid operation\00"
@.str.7 = [43 x i8] c"FPE: floating point sudirript out of range\00"
@.str.8 = [19 x i8] c"FPE at address %p\0A\00"
@.str.9 = [16 x i8] c"frame(%03d): %s\00"
define void @fpe(i32 %0, %struct.TYPE_3__* nocapture %1, i8* nocapture readnone %2) {
%4 = alloca [256 x i8*]
%5 = bitcast [256 x i8*]* %4 to i8*
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%7 = load i32, i32* %6
switch i32 %7, label %24 [
i32 129, label %8
i32 128, label %10
i32 135, label %12
i32 133, label %14
i32 130, label %16
i32 132, label %18
i32 134, label %20
i32 131, label %22
]
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %28
10: ; preds = %3
%11 = tail call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %28
12: ; preds = %3
%13 = tail call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %28
14: ; preds = %3
%15 = tail call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %28
16: ; preds = %3
%17 = tail call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %28
18: ; preds = %3
%19 = tail call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %28
20: ; preds = %3
%21 = tail call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
br label %28
22: ; preds = %3
%23 = tail call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0))
br label %28
24: ; preds = %3
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %22, %20, %18, %16, %14, %12, %10, %8
%29 = getelementptr inbounds [256 x i8*], [256 x i8*]* %4, i64 0, i64 0
%30 = call i32 @backtrace(i8** %29, i32 2048)
%31 = call i8** @backtrace_symbols(i8** %29, i32 %30)
%32 = icmp sgt i32 %30, 0
br i1 %32, label %33, label %43
33: ; preds = %28
%34 = zext i32 %30 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %41, %35 ]
%37 = getelementptr inbounds i8*, i8** %31, i64 %36
%38 = load i8*, i8** %37
%39 = trunc i64 %36 to i32
%40 = call i32 (i8*, ...) @log_err(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %39, i8* %38)
%41 = add nuw nsw i64 %36, 1
%42 = icmp eq i64 %41, %34
br i1 %42, label %43, label %35
43: ; preds = %35, %28
%44 = call i32 (...) @abort()
unreachable
}