#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*/ acosh(double);
int /*<<< orphan*/ asin(double);
scalar_t__ errno;
int /*<<< orphan*/ log(double);
int /*<<< orphan*/ pow(int, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remainder(double, double);
int /*<<< orphan*/ sqrt(double);
int test_exception() {
  int errs = 0;
  printf("Checking that exceptional lib calls set errno\n");
  errs += (errno = 0, pow(-3, 4.4),
           (0 != errno ? 0
                       : (printf("%s - errno %d not set at %d\n",
                                 "pow(-3, 4.4)", errno, 155),
                          1)));
  errs +=
      (errno = 0, log(-3.0),
       (0 != errno
            ? 0
            : (printf("%s - errno %d not set at %d\n", "log(-3.0)", errno, 156),
               1)));
  errs += (errno = 0, sqrt(-0.001),
           (0 != errno ? 0
                       : (printf("%s - errno %d not set at %d\n",
                                 "sqrt(-0.001)", errno, 157),
                          1)));
  errs += (errno = 0, asin(1.0001),
           (0 != errno ? 0
                       : (printf("%s - errno %d not set at %d\n",
                                 "asin(1.0001)", errno, 158),
                          1)));
  errs += (errno = 0, acosh(0.999),
           (0 != errno ? 0
                       : (printf("%s - errno %d not set at %d\n",
                                 "acosh(0.999)", errno, 166),
                          1)));
  errs += (errno = 0, remainder(3.3, 0.0),
           (0 != errno ? 0
                       : (printf("%s - errno %d not set at %d\n",
                                 "remainder(3.3, 0.0)", errno, 167),
                          1)));
  return errs;
}


x86 assembly (clang, -O0):
<test_exception>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e4c(%rip),%rax
movq   $0x0,(%rax)
mov    $0xfffffffd,%edi
movsd  0xe58(%rip),%xmm0
call   1080 <pow@plt>
xor    %eax,%eax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%rax
je     11c9 <test_exception+0x59>
xor    %eax,%eax
mov    %eax,-0x8(%rbp)
jmp    11f5 <test_exception+0x85>
mov    0x2e10(%rip),%rax
mov    (%rax),%rdx
lea    0xe85(%rip),%rdi
lea    0xe9b(%rip),%rsi
mov    $0x9b,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2ddb(%rip),%rax
movq   $0x0,(%rax)
movsd  0xdf4(%rip),%xmm0
call   1070 <log@plt>
xor    %eax,%eax
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%rax
je     1235 <test_exception+0xc5>
xor    %eax,%eax
mov    %eax,-0xc(%rbp)
jmp    1261 <test_exception+0xf1>
mov    0x2da4(%rip),%rax
mov    (%rax),%rdx
lea    0xe19(%rip),%rdi
lea    0xe3c(%rip),%rsi
mov    $0x9c,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2d6f(%rip),%rax
movq   $0x0,(%rax)
movsd  0xd90(%rip),%xmm0
call   1090 <sqrt@plt>
xor    %eax,%eax
mov    0x2d52(%rip),%rcx
cmp    (%rcx),%rax
je     12a1 <test_exception+0x131>
xor    %eax,%eax
mov    %eax,-0x10(%rbp)
jmp    12cd <test_exception+0x15d>
mov    0x2d38(%rip),%rax
mov    (%rax),%rdx
lea    0xdad(%rip),%rdi
lea    0xdda(%rip),%rsi
mov    $0x9d,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2d03(%rip),%rax
movq   $0x0,(%rax)
movsd  0xd2c(%rip),%xmm0
call   1050 <asin@plt>
xor    %eax,%eax
mov    0x2ce6(%rip),%rcx
cmp    (%rcx),%rax
je     130d <test_exception+0x19d>
xor    %eax,%eax
mov    %eax,-0x14(%rbp)
jmp    1339 <test_exception+0x1c9>
mov    0x2ccc(%rip),%rax
mov    (%rax),%rdx
lea    0xd41(%rip),%rdi
lea    0xd7b(%rip),%rsi
mov    $0x9e,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2c97(%rip),%rax
movq   $0x0,(%rax)
movsd  0xcc8(%rip),%xmm0
call   1040 <acosh@plt>
xor    %eax,%eax
mov    0x2c7a(%rip),%rcx
cmp    (%rcx),%rax
je     1379 <test_exception+0x209>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    13a5 <test_exception+0x235>
mov    0x2c60(%rip),%rax
mov    (%rax),%rdx
lea    0xcd5(%rip),%rdi
lea    0xd1c(%rip),%rsi
mov    $0xa6,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2c2b(%rip),%rax
movq   $0x0,(%rax)
movsd  0xc64(%rip),%xmm0
xorps  %xmm1,%xmm1
call   1060 <remainder@plt>
xor    %eax,%eax
mov    0x2c0b(%rip),%rcx
cmp    (%rcx),%rax
je     13e8 <test_exception+0x278>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    1414 <test_exception+0x2a4>
mov    0x2bf1(%rip),%rax
mov    (%rax),%rdx
lea    0xc66(%rip),%rdi
lea    0xcba(%rip),%rsi
mov    $0xa7,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_exception>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf0d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e42(%rip),%r14
movq   $0x0,(%r14)
movsd  0xe53(%rip),%xmm0
mov    $0xfffffffd,%edi
call   1090 <pow@plt>
xor    %ebx,%ebx
cmpq   $0x0,(%r14)
mov    $0x0,%eax
jne    11e5 <test_exception+0x65>
lea    0xe65(%rip),%rdi
lea    0xe7b(%rip),%rsi
xor    %edx,%edx
mov    $0x9b,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
mov    %eax,0x4(%rsp)
movq   $0x0,(%r14)
movsd  0xe10(%rip),%xmm0
call   1080 <log@plt>
cmpq   $0x0,(%r14)
jne    1224 <test_exception+0xa4>
lea    0xe26(%rip),%rdi
lea    0xe49(%rip),%rsi
xor    %edx,%edx
mov    $0x9c,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
movq   $0x0,(%r14)
movsd  0xddd(%rip),%xmm0
call   10a0 <sqrt@plt>
xor    %r12d,%r12d
cmpq   $0x0,(%r14)
mov    $0x0,%r13d
jne    1269 <test_exception+0xe9>
lea    0xde2(%rip),%rdi
lea    0xe0f(%rip),%rsi
xor    %edx,%edx
mov    $0x9d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r13d
movq   $0x0,(%r14)
movsd  0xda0(%rip),%xmm0
call   1060 <asin@plt>
cmpq   $0x0,(%r14)
jne    12a5 <test_exception+0x125>
lea    0xda6(%rip),%rdi
lea    0xde0(%rip),%rsi
xor    %edx,%edx
mov    $0x9e,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r12d
movq   $0x0,(%r14)
movsd  0xd6c(%rip),%xmm0
call   1050 <acosh@plt>
xor    %ebp,%ebp
cmpq   $0x0,(%r14)
mov    $0x0,%r15d
jne    12e9 <test_exception+0x169>
lea    0xd62(%rip),%rdi
lea    0xda9(%rip),%rsi
xor    %edx,%edx
mov    $0xa6,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r15d
movq   $0x0,(%r14)
movsd  0xd30(%rip),%xmm0
xorps  %xmm1,%xmm1
call   1070 <remainder@plt>
cmpq   $0x0,(%r14)
jne    1327 <test_exception+0x1a7>
lea    0xd23(%rip),%rdi
lea    0xd77(%rip),%rsi
xor    %edx,%edx
mov    $0xa7,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
add    0x4(%rsp),%ebx
add    %r13d,%ebx
add    %r12d,%ebx
add    %r15d,%ebx
add    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Checking that exceptional lib calls set errno\0A\00"
@errno = global i64 0
@.str.1 = [29 x i8] c"%s - errno %d not set at %d\0A\00"
@.str.2 = [13 x i8] c"pow(-3, 4.4)\00"
@.str.3 = [10 x i8] c"log(-3.0)\00"
@.str.4 = [13 x i8] c"sqrt(-0.001)\00"
@.str.5 = [13 x i8] c"asin(1.0001)\00"
@.str.6 = [13 x i8] c"acosh(0.999)\00"
@.str.7 = [20 x i8] c"remainder(3.3, 0.0)\00"
define i32 @test_exception() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* @errno
%3 = call i32 @pow(i32 -3, double 4.400000e+00)
%4 = load i64, i64* @errno
%5 = icmp ne i64 0, %4
br i1 %5, label %6, label %7
6: ; preds = %0
br label %10
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %8, i32 155)
br label %10
10: ; preds = %7, %6
%11 = phi i32 [ 0, %6 ], [ 1, %7 ]
%12 = load i32, i32* %1
%13 = add nsw i32 %12, %11
store i32 %13, i32* %1
store i64 0, i64* @errno
%14 = call i32 @log(double -3.000000e+00)
%15 = load i64, i64* @errno
%16 = icmp ne i64 0, %15
br i1 %16, label %17, label %18
17: ; preds = %10
br label %21
18: ; preds = %10
%19 = load i64, i64* @errno
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 %19, i32 156)
br label %21
21: ; preds = %18, %17
%22 = phi i32 [ 0, %17 ], [ 1, %18 ]
%23 = load i32, i32* %1
%24 = add nsw i32 %23, %22
store i32 %24, i32* %1
store i64 0, i64* @errno
%25 = call i32 @sqrt(double -1.000000e-03)
%26 = load i64, i64* @errno
%27 = icmp ne i64 0, %26
br i1 %27, label %28, label %29
28: ; preds = %21
br label %32
29: ; preds = %21
%30 = load i64, i64* @errno
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 %30, i32 157)
br label %32
32: ; preds = %29, %28
%33 = phi i32 [ 0, %28 ], [ 1, %29 ]
%34 = load i32, i32* %1
%35 = add nsw i32 %34, %33
store i32 %35, i32* %1
store i64 0, i64* @errno
%36 = call i32 @asin(double 1.000100e+00)
%37 = load i64, i64* @errno
%38 = icmp ne i64 0, %37
br i1 %38, label %39, label %40
39: ; preds = %32
br label %43
40: ; preds = %32
%41 = load i64, i64* @errno
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %41, i32 158)
br label %43
43: ; preds = %40, %39
%44 = phi i32 [ 0, %39 ], [ 1, %40 ]
%45 = load i32, i32* %1
%46 = add nsw i32 %45, %44
store i32 %46, i32* %1
store i64 0, i64* @errno
%47 = call i32 @acosh(double 0x3FEFF7CED916872B)
%48 = load i64, i64* @errno
%49 = icmp ne i64 0, %48
br i1 %49, label %50, label %51
50: ; preds = %43
br label %54
51: ; preds = %43
%52 = load i64, i64* @errno
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 %52, i32 166)
br label %54
54: ; preds = %51, %50
%55 = phi i32 [ 0, %50 ], [ 1, %51 ]
%56 = load i32, i32* %1
%57 = add nsw i32 %56, %55
store i32 %57, i32* %1
store i64 0, i64* @errno
%58 = call i32 @remainder(double 3.300000e+00, double 0.000000e+00)
%59 = load i64, i64* @errno
%60 = icmp ne i64 0, %59
br i1 %60, label %61, label %62
61: ; preds = %54
br label %65
62: ; preds = %54
%63 = load i64, i64* @errno
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i64 %63, i32 167)
br label %65
65: ; preds = %62, %61
%66 = phi i32 [ 0, %61 ], [ 1, %62 ]
%67 = load i32, i32* %1
%68 = add nsw i32 %67, %66
store i32 %68, i32* %1
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
@errno = global i64 0
@.str.1 = [29 x i8] c"%s - errno %d not set at %d\0A\00"
@.str.2 = [13 x i8] c"pow(-3, 4.4)\00"
@.str.3 = [10 x i8] c"log(-3.0)\00"
@.str.4 = [13 x i8] c"sqrt(-0.001)\00"
@.str.5 = [13 x i8] c"asin(1.0001)\00"
@.str.6 = [13 x i8] c"acosh(0.999)\00"
@.str.7 = [20 x i8] c"remainder(3.3, 0.0)\00"
@str = [46 x i8] c"Checking that exceptional lib calls set errno\00"
define i32 @test_exception() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
store i64 0, i64* @errno
%2 = tail call i32 @pow(i32 -3, double 4.400000e+00)
%3 = load i64, i64* @errno
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 0, i32 155)
br label %7
7: ; preds = %0, %5
%8 = phi i32 [ 1, %5 ], [ 0, %0 ]
store i64 0, i64* @errno
%9 = tail call i32 @log(double -3.000000e+00)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 0, i32 156)
br label %14
14: ; preds = %7, %12
%15 = phi i32 [ 1, %12 ], [ 0, %7 ]
store i64 0, i64* @errno
%16 = tail call i32 @sqrt(double -1.000000e-03)
%17 = load i64, i64* @errno
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 0, i32 157)
br label %21
21: ; preds = %14, %19
%22 = phi i32 [ 1, %19 ], [ 0, %14 ]
store i64 0, i64* @errno
%23 = tail call i32 @asin(double 1.000100e+00)
%24 = load i64, i64* @errno
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 0, i32 158)
br label %28
28: ; preds = %21, %26
%29 = phi i32 [ 1, %26 ], [ 0, %21 ]
store i64 0, i64* @errno
%30 = tail call i32 @acosh(double 0x3FEFF7CED916872B)
%31 = load i64, i64* @errno
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 0, i32 166)
br label %35
35: ; preds = %28, %33
%36 = phi i32 [ 1, %33 ], [ 0, %28 ]
store i64 0, i64* @errno
%37 = tail call i32 @remainder(double 3.300000e+00, double 0.000000e+00)
%38 = load i64, i64* @errno
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i64 0, i32 167)
br label %42
42: ; preds = %35, %40
%43 = phi i32 [ 1, %40 ], [ 0, %35 ]
%44 = add nuw nsw i32 %15, %8
%45 = add nuw nsw i32 %44, %22
%46 = add nuw nsw i32 %45, %29
%47 = add nuw nsw i32 %46, %36
%48 = add nuw nsw i32 %47, %43
ret i32 %48
}