#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ fpregs;
};
struct TYPE_4__ {
  TYPE_1__ uc_mcontext;
};
typedef TYPE_2__ ucontext_t;
struct _fpstate {
  int mxcsr;
  int swd;
  int cwd;
};
typedef int /*<<< orphan*/ siginfo_t;

/* Variables and functions */
int SIGFPE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ print_backtrace(int);
int /*<<< orphan*/ stderr;
void fpe_handler(int signal, siginfo_t *siginfo, void *uc) {
  struct _fpstate *fps =
      (struct _fpstate *)((ucontext_t *)uc)->uc_mcontext.fpregs;
  if (signal == SIGFPE) {
    int fpe_exc = (fps->mxcsr & 0x0000003F) | (fps->swd & 0x0000003F);
    fps->mxcsr |= 0x00001F90;
    fps->cwd |= 0x0000003F;
    fprintf(stderr, "*******************************************\n");
    fprintf(stderr, "Floating point exception:");
    if (fpe_exc & 1)
      fprintf(stderr, " invalid");
    if (fpe_exc & 2)
      fprintf(stderr, " denormal");
    if (fpe_exc & 4)
      fprintf(stderr, " zero");
    if (fpe_exc & 16)
      fprintf(stderr, " undeflow");
    if (fpe_exc & 8)
      fprintf(stderr, " overflow");
    if (fpe_exc & 32)
      fprintf(stderr, " precision");
    fprintf(stderr, "\n");
    print_backtrace(2);
    fprintf(stderr, "*******************************************\n");
  }
}


x86 assembly (clang, -O0):
<fpe_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ea0(%rip),%rcx
cmp    (%rcx),%eax
jne    12b9 <fpe_handler+0x199>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
and    $0x3f,%eax
mov    -0x20(%rbp),%rcx
mov    0x4(%rcx),%ecx
and    $0x3f,%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
or     $0x1f90,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%ecx
or     $0x3f,%ecx
mov    %ecx,0x8(%rax)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11d1 <fpe_handler+0xb1>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11f5 <fpe_handler+0xd5>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1219 <fpe_handler+0xf9>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     123d <fpe_handler+0x11d>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1261 <fpe_handler+0x141>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1285 <fpe_handler+0x165>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xd96(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1030 <print_backtrace@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fpe_handler>:
push   %rbp
push   %rbx
push   %rax
mov    0x2ebe(%rip),%rax
cmp    %edi,(%rax)
jne    11d5 <fpe_handler+0xb5>
mov    (%rdx),%rax
mov    (%rax),%ecx
mov    0x4(%rax),%ebp
or     %ecx,%ebp
or     $0x1f90,%ecx
mov    %ecx,(%rax)
orb    $0x3f,0x8(%rax)
mov    0x2e89(%rip),%rbx
mov    (%rbx),%edi
lea    0xea8(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xec7(%rip),%rsi
call   1040 <fprintf@plt>
test   $0x1,%bpl
jne    11dc <fpe_handler+0xbc>
test   $0x2,%bpl
jne    11f0 <fpe_handler+0xd0>
test   $0x4,%bpl
jne    1208 <fpe_handler+0xe8>
test   $0x10,%bpl
jne    1220 <fpe_handler+0x100>
test   $0x8,%bpl
jne    1238 <fpe_handler+0x118>
test   $0x20,%bpl
je     11a9 <fpe_handler+0x89>
mov    (%rbx),%edi
lea    0xed0(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1030 <print_backtrace@plt>
mov    (%rbx),%edi
lea    0xe36(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    (%rbx),%edi
lea    0xe62(%rip),%rsi
call   1040 <fprintf@plt>
test   $0x2,%bpl
je     1177 <fpe_handler+0x57>
mov    (%rbx),%edi
lea    0xe57(%rip),%rsi
call   1040 <fprintf@plt>
test   $0x4,%bpl
je     1181 <fpe_handler+0x61>
mov    (%rbx),%edi
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
test   $0x10,%bpl
je     118b <fpe_handler+0x6b>
mov    (%rbx),%edi
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
test   $0x8,%bpl
je     1195 <fpe_handler+0x75>
mov    (%rbx),%edi
lea    0xe29(%rip),%rsi
call   1040 <fprintf@plt>
test   $0x20,%bpl
jne    119b <fpe_handler+0x7b>
jmp    11a9 <fpe_handler+0x89>

LLVM IR (-O0):
%struct._fpstate = type { i32, i32, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i64 }
@SIGFPE = global i32 0
@stderr = global i32 0
@.str = [45 x i8] c"*******************************************\0A\00"
@.str.1 = [26 x i8] c"Floating point exception:\00"
@.str.2 = [9 x i8] c" invalid\00"
@.str.3 = [10 x i8] c" denormal\00"
@.str.4 = [6 x i8] c" zero\00"
@.str.5 = [10 x i8] c" undeflow\00"
@.str.6 = [10 x i8] c" overflow\00"
@.str.7 = [11 x i8] c" precision\00"
@.str.8 = [2 x i8] c"\0A\00"
define void @fpe_handler(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca %struct._fpstate*
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = bitcast i8* %9 to %struct.TYPE_4__*
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %10, i32 0, i32 0
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to %struct._fpstate*
store %struct._fpstate* %14, %struct._fpstate** %7
%15 = load i32, i32* %4
%16 = load i32, i32* @SIGFPE
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %87
18: ; preds = %3
%19 = load %struct._fpstate*, %struct._fpstate** %7
%20 = getelementptr inbounds %struct._fpstate, %struct._fpstate* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = and i32 %21, 63
%23 = load %struct._fpstate*, %struct._fpstate** %7
%24 = getelementptr inbounds %struct._fpstate, %struct._fpstate* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = and i32 %25, 63
%27 = or i32 %22, %26
store i32 %27, i32* %8
%28 = load %struct._fpstate*, %struct._fpstate** %7
%29 = getelementptr inbounds %struct._fpstate, %struct._fpstate* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = or i32 %30, 8080
store i32 %31, i32* %29
%32 = load %struct._fpstate*, %struct._fpstate** %7
%33 = getelementptr inbounds %struct._fpstate, %struct._fpstate* %32, i32 0, i32 2
%34 = load i32, i32* %33
%35 = or i32 %34, 63
store i32 %35, i32* %33
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* %8
%41 = and i32 %40, 1
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %18
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %43, %18
%47 = load i32, i32* %8
%48 = and i32 %47, 2
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %50, %46
%54 = load i32, i32* %8
%55 = and i32 %54, 4
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %57, %53
%61 = load i32, i32* %8
%62 = and i32 %61, 16
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %67
67: ; preds = %64, %60
%68 = load i32, i32* %8
%69 = and i32 %68, 8
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %74
74: ; preds = %71, %67
%75 = load i32, i32* %8
%76 = and i32 %75, 32
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %74
%79 = load i32, i32* @stderr
%80 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %81
81: ; preds = %78, %74
%82 = load i32, i32* @stderr
%83 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%84 = call i32 @print_backtrace(i32 2)
%85 = load i32, i32* @stderr
%86 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %87
87: ; preds = %81, %3
ret void
}

LLVM IR (-O2):
%struct._fpstate = type { i32, i32, i32 }
@SIGFPE = global i32 0
@stderr = global i32 0
@.str = [45 x i8] c"*******************************************\0A\00"
@.str.1 = [26 x i8] c"Floating point exception:\00"
@.str.2 = [9 x i8] c" invalid\00"
@.str.3 = [10 x i8] c" denormal\00"
@.str.4 = [6 x i8] c" zero\00"
@.str.5 = [10 x i8] c" undeflow\00"
@.str.6 = [10 x i8] c" overflow\00"
@.str.7 = [11 x i8] c" precision\00"
@.str.8 = [2 x i8] c"\0A\00"
define void @fpe_handler(i32 %0, i32* nocapture readnone %1, i8* nocapture %2) {
%4 = bitcast i8* %2 to i64*
%5 = load i64, i64* %4
%6 = inttoptr i64 %5 to %struct._fpstate*
%7 = load i32, i32* @SIGFPE
%8 = icmp eq i32 %7, %0
br i1 %8, label %9, label %64
9: ; preds = %3
%10 = getelementptr inbounds %struct._fpstate, %struct._fpstate* %6, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct._fpstate, %struct._fpstate* %6, i64 0, i32 1
%13 = load i32, i32* %12
%14 = or i32 %13, %11
%15 = or i32 %11, 8080
store i32 %15, i32* %10
%16 = getelementptr inbounds %struct._fpstate, %struct._fpstate* %6, i64 0, i32 2
%17 = load i32, i32* %16
%18 = or i32 %17, 63
store i32 %18, i32* %16
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%23 = and i32 %14, 1
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %9
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %25, %9
%29 = and i32 %14, 2
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %31, %28
%35 = and i32 %14, 4
%36 = icmp eq i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %37, %34
%41 = and i32 %14, 16
%42 = icmp eq i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %43, %40
%47 = and i32 %14, 8
%48 = icmp eq i32 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %52
52: ; preds = %49, %46
%53 = and i32 %14, 32
%54 = icmp eq i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = tail call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %58
58: ; preds = %55, %52
%59 = load i32, i32* @stderr
%60 = tail call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%61 = tail call i32 @print_backtrace(i32 2)
%62 = load i32, i32* @stderr
%63 = tail call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %64
64: ; preds = %58, %3
ret void
}