#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ FE_ALL_EXCEPT;
int /*<<< orphan*/ FE_DIVBYZERO;
int /*<<< orphan*/ FE_INEXACT;
int /*<<< orphan*/ FE_INVALID;
int /*<<< orphan*/ FE_OVERFLOW;
int /*<<< orphan*/ FE_UNDERFLOW;
int SIGFPE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fetestexcept(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void fpe_handler(int sig) {
  if (sig != SIGFPE)
    return;
  printf("UPS! Floating Point Exception \n");
  if (fetestexcept(FE_INVALID))
    printf("FE_INVALID\n");
  if (fetestexcept(FE_INEXACT))
    printf("FE_INEXACT\n");
  if (fetestexcept(FE_DIVBYZERO))
    printf("FE_DIVBYZERO\n");
  if (fetestexcept(FE_OVERFLOW))
    printf("FE_OVERFLOW\n");
  if (fetestexcept(FE_UNDERFLOW))
    printf("FE_UNDERFLOW\n");
  if (fetestexcept(FE_ALL_EXCEPT) == 0)
    printf("None exceptions\n");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<fpe_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%eax
je     1153 <fpe_handler+0x23>
add    $0x10,%rsp
pop    %rbp
ret
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
cmp    $0x0,%rax
je     1183 <fpe_handler+0x53>
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
cmp    $0x0,%rax
je     11a7 <fpe_handler+0x77>
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
cmp    $0x0,%rax
je     11cb <fpe_handler+0x9b>
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
cmp    $0x0,%rax
je     11ef <fpe_handler+0xbf>
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
cmp    $0x0,%rax
je     1213 <fpe_handler+0xe3>
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
cmp    $0x0,%rax
jne    1237 <fpe_handler+0x107>
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<fpe_handler>:
push   %rax
mov    0x2ea0(%rip),%rax
cmp    %edi,(%rax)
je     113e <fpe_handler+0xe>
pop    %rax
ret
lea    0xebb(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
test   %rax,%rax
je     1169 <fpe_handler+0x39>
lea    0xefc(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
test   %rax,%rax
je     1188 <fpe_handler+0x58>
lea    0xed2(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
test   %rax,%rax
je     11a7 <fpe_handler+0x77>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
test   %rax,%rax
je     11c6 <fpe_handler+0x96>
lea    0xe7b(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
test   %rax,%rax
je     11e5 <fpe_handler+0xb5>
lea    0xe4f(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1030 <fetestexcept@plt>
test   %rax,%rax
jne    1204 <fpe_handler+0xd4>
lea    0xe20(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SIGFPE = global i32 0
@.str = [32 x i8] c"UPS! Floating Point Exception \0A\00"
@FE_INVALID = global i32 0
@.str.1 = [12 x i8] c"FE_INVALID\0A\00"
@FE_INEXACT = global i32 0
@.str.2 = [12 x i8] c"FE_INEXACT\0A\00"
@FE_DIVBYZERO = global i32 0
@.str.3 = [14 x i8] c"FE_DIVBYZERO\0A\00"
@FE_OVERFLOW = global i32 0
@.str.4 = [13 x i8] c"FE_OVERFLOW\0A\00"
@FE_UNDERFLOW = global i32 0
@.str.5 = [14 x i8] c"FE_UNDERFLOW\0A\00"
@FE_ALL_EXCEPT = global i32 0
@.str.6 = [17 x i8] c"None exceptions\0A\00"
@EXIT_FAILURE = global i32 0
define void @fpe_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGFPE
%5 = icmp ne i32 %3, %4
br i1 %5, label %6, label %7
6: ; preds = %1
ret void
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @FE_INVALID
%10 = call i64 @fetestexcept(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %7
%15 = load i32, i32* @FE_INEXACT
%16 = call i64 @fetestexcept(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* @FE_DIVBYZERO
%22 = call i64 @fetestexcept(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = load i32, i32* @FE_OVERFLOW
%28 = call i64 @fetestexcept(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = load i32, i32* @FE_UNDERFLOW
%34 = call i64 @fetestexcept(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
%39 = load i32, i32* @FE_ALL_EXCEPT
%40 = call i64 @fetestexcept(i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
}

LLVM IR (-O2):
@SIGFPE = global i32 0
@FE_INVALID = global i32 0
@FE_INEXACT = global i32 0
@FE_DIVBYZERO = global i32 0
@FE_OVERFLOW = global i32 0
@FE_UNDERFLOW = global i32 0
@FE_ALL_EXCEPT = global i32 0
@EXIT_FAILURE = global i32 0
@str = [31 x i8] c"UPS! Floating Point Exception \00"
@str.7 = [16 x i8] c"None exceptions\00"
@str.8 = [13 x i8] c"FE_UNDERFLOW\00"
@str.9 = [12 x i8] c"FE_OVERFLOW\00"
@str.10 = [13 x i8] c"FE_DIVBYZERO\00"
@str.11 = [11 x i8] c"FE_INEXACT\00"
@str.12 = [11 x i8] c"FE_INVALID\00"
define void @fpe_handler(i32 %0) {
%2 = load i32, i32* @SIGFPE
%3 = icmp eq i32 %2, %0
br i1 %3, label %5, label %4
4: ; preds = %1
ret void
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%7 = load i32, i32* @FE_INVALID
%8 = tail call i64 @fetestexcept(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.12, i64 0, i64 0))
br label %12
12: ; preds = %10, %5
%13 = load i32, i32* @FE_INEXACT
%14 = tail call i64 @fetestexcept(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.11, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = load i32, i32* @FE_DIVBYZERO
%20 = tail call i64 @fetestexcept(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.10, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = load i32, i32* @FE_OVERFLOW
%26 = tail call i64 @fetestexcept(i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* @FE_UNDERFLOW
%32 = tail call i64 @fetestexcept(i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
%37 = load i32, i32* @FE_ALL_EXCEPT
%38 = tail call i64 @fetestexcept(i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
br label %42
42: ; preds = %40, %36
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @exit(i32 %43)
unreachable
}