#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 */
scalar_t__ acosh(double volatile);
scalar_t__ asin(double volatile);
scalar_t__ errno;
scalar_t__ log(double volatile);
scalar_t__ pow(double volatile, double volatile);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ remainder(double volatile, double volatile);
scalar_t__ sqrt(double volatile);
int test_exception(void) {
  int errs = 0;
  volatile double x;
  volatile double y;
  printf("Checking that exceptional lib calls set errno\n");
  x = -3.0;
  y = 4.4;
  errs +=
      (errno = 0, (void)pow(x, y),
       (0 != errno
            ? 0
            : (printf("%s - errno %d not set at %d\n", "pow(x, y)", errno, 203),
               1)));
  errs +=
      (errno = 0, (void)log(x),
       (0 != errno
            ? 0
            : (printf("%s - errno %d not set at %d\n", "log(x)", errno, 204),
               1)));
  x = -0.001;
  errs +=
      (errno = 0, (void)sqrt(x),
       (0 != errno
            ? 0
            : (printf("%s - errno %d not set at %d\n", "sqrt(x)", errno, 206),
               1)));
  x = 1.0001;
  errs +=
      (errno = 0, (void)asin(x),
       (0 != errno
            ? 0
            : (printf("%s - errno %d not set at %d\n", "asin(x)", errno, 208),
               1)));
  x = 0.999;
  errs +=
      (errno = 0, (void)acosh(x),
       (0 != errno
            ? 0
            : (printf("%s - errno %d not set at %d\n", "acosh(x)", errno, 218),
               1)));
  x = 3.3;
  y = 0.0;
  errs += (errno = 0, (void)remainder(x, y),
           (0 != errno ? 0
                       : (printf("%s - errno %d not set at %d\n",
                                 "remainder(x, y)", errno, 220),
                          1)));
  return errs;
}


x86 assembly (clang, -O0):
<test_exception>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  0xe73(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe5e(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    0x2e32(%rip),%rax
movq   $0x0,(%rax)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1080 <pow@plt>
xor    %eax,%eax
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%rax
je     11e0 <test_exception+0x70>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    120c <test_exception+0x9c>
mov    0x2df9(%rip),%rax
mov    (%rax),%rdx
lea    0xe6e(%rip),%rdi
lea    0xe84(%rip),%rsi
mov    $0xcb,%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    0x2dc4(%rip),%rax
movq   $0x0,(%rax)
movsd  -0x10(%rbp),%xmm0
call   1070 <log@plt>
xor    %eax,%eax
mov    0x2daa(%rip),%rcx
cmp    (%rcx),%rax
je     1249 <test_exception+0xd9>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    1275 <test_exception+0x105>
mov    0x2d90(%rip),%rax
mov    (%rax),%rdx
lea    0xe05(%rip),%rdi
lea    0xe25(%rip),%rsi
mov    $0xcc,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movsd  0xd8a(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2d4e(%rip),%rax
movq   $0x0,(%rax)
movsd  -0x10(%rbp),%xmm0
call   1090 <sqrt@plt>
xor    %eax,%eax
mov    0x2d34(%rip),%rcx
cmp    (%rcx),%rax
je     12bf <test_exception+0x14f>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    12eb <test_exception+0x17b>
mov    0x2d1a(%rip),%rax
mov    (%rax),%rdx
lea    0xd8f(%rip),%rdi
lea    0xdb6(%rip),%rsi
mov    $0xce,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movsd  0xd1c(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2cd8(%rip),%rax
movq   $0x0,(%rax)
movsd  -0x10(%rbp),%xmm0
call   1050 <asin@plt>
xor    %eax,%eax
mov    0x2cbe(%rip),%rcx
cmp    (%rcx),%rax
je     1335 <test_exception+0x1c5>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    1361 <test_exception+0x1f1>
mov    0x2ca4(%rip),%rax
mov    (%rax),%rdx
lea    0xd19(%rip),%rdi
lea    0xd48(%rip),%rsi
mov    $0xd0,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movsd  0xcae(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2c62(%rip),%rax
movq   $0x0,(%rax)
movsd  -0x10(%rbp),%xmm0
call   1040 <acosh@plt>
xor    %eax,%eax
mov    0x2c48(%rip),%rcx
cmp    (%rcx),%rax
je     13ab <test_exception+0x23b>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    13d7 <test_exception+0x267>
mov    0x2c2e(%rip),%rax
mov    (%rax),%rdx
lea    0xca3(%rip),%rdi
lea    0xcda(%rip),%rsi
mov    $0xda,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movsd  0xc40(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    0x2be4(%rip),%rax
movq   $0x0,(%rax)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1060 <remainder@plt>
xor    %eax,%eax
mov    0x2bc5(%rip),%rcx
cmp    (%rcx),%rax
je     142e <test_exception+0x2be>
xor    %eax,%eax
mov    %eax,-0x30(%rbp)
jmp    145a <test_exception+0x2ea>
mov    0x2bab(%rip),%rax
mov    (%rax),%rdx
lea    0xc20(%rip),%rdi
lea    0xc60(%rip),%rsi
mov    $0xdc,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_exception>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
movabs $0xc008000000000000,%rax
mov    %rax,(%rsp)
movabs $0x401199999999999a,%rax
99 11 40
mov    %rax,0x8(%rsp)
mov    0x2e22(%rip),%r14
movq   $0x0,(%r14)
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1090 <pow@plt>
xor    %ebx,%ebx
cmpq   $0x0,(%r14)
mov    $0x0,%eax
jne    1203 <test_exception+0x83>
lea    0xe17(%rip),%rdi
lea    0xe2d(%rip),%rsi
xor    %edx,%edx
mov    $0xcb,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
mov    %eax,0x14(%rsp)
movq   $0x0,(%r14)
movsd  (%rsp),%xmm0
call   1080 <log@plt>
cmpq   $0x0,(%r14)
jne    123f <test_exception+0xbf>
lea    0xddb(%rip),%rdi
lea    0xdfb(%rip),%rsi
xor    %edx,%edx
mov    $0xcc,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
movabs $0xbf50624dd2f1a9fc,%rax
62 50 bf
mov    %rax,(%rsp)
movq   $0x0,(%r14)
movsd  (%rsp),%xmm0
call   10a0 <sqrt@plt>
xor    %r12d,%r12d
cmpq   $0x0,(%r14)
mov    $0x0,%r13d
jne    128f <test_exception+0x10f>
lea    0xd8c(%rip),%rdi
lea    0xdb3(%rip),%rsi
xor    %edx,%edx
mov    $0xce,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r13d
movabs $0x3ff00068db8bac71,%rax
mov    %rax,(%rsp)
movq   $0x0,(%r14)
movsd  (%rsp),%xmm0
call   1060 <asin@plt>
cmpq   $0x0,(%r14)
jne    12d6 <test_exception+0x156>
lea    0xd45(%rip),%rdi
lea    0xd74(%rip),%rsi
xor    %edx,%edx
mov    $0xd0,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r12d
movabs $0x3feff7ced916872b,%rax
f7 ef 3f
mov    %rax,(%rsp)
movq   $0x0,(%r14)
movsd  (%rsp),%xmm0
call   1050 <acosh@plt>
xor    %ebp,%ebp
cmpq   $0x0,(%r14)
mov    $0x0,%r15d
jne    1325 <test_exception+0x1a5>
lea    0xcf6(%rip),%rdi
lea    0xd2d(%rip),%rsi
xor    %edx,%edx
mov    $0xda,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r15d
movabs $0x400a666666666666,%rax
66 0a 40
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,(%r14)
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1070 <remainder@plt>
cmpq   $0x0,(%r14)
jne    137a <test_exception+0x1fa>
lea    0xca0(%rip),%rdi
lea    0xce0(%rip),%rsi
xor    %edx,%edx
mov    $0xdc,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
add    0x14(%rsp),%ebx
add    %r13d,%ebx
add    %r12d,%ebx
add    %r15d,%ebx
add    %ebp,%ebx
mov    %ebx,%eax
add    $0x18,%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 = [10 x i8] c"pow(x, y)\00"
@.str.3 = [7 x i8] c"log(x)\00"
@.str.4 = [8 x i8] c"sqrt(x)\00"
@.str.5 = [8 x i8] c"asin(x)\00"
@.str.6 = [9 x i8] c"acosh(x)\00"
@.str.7 = [16 x i8] c"remainder(x, y)\00"
define i32 @test_exception() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store volatile double -3.000000e+00, double* %2
store volatile double 4.400000e+00, double* %3
store i64 0, i64* @errno
%5 = load volatile double, double* %2
%6 = load volatile double, double* %3
%7 = call i64 @pow(double %5, double %6)
%8 = load i64, i64* @errno
%9 = icmp ne i64 0, %8
br i1 %9, label %10, label %11
10: ; preds = %0
br label %14
11: ; preds = %0
%12 = load i64, i64* @errno
%13 = 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.2, i64 0, i64 0), i64 %12, i32 203)
br label %14
14: ; preds = %11, %10
%15 = phi i32 [ 0, %10 ], [ 1, %11 ]
%16 = load i32, i32* %1
%17 = add nsw i32 %16, %15
store i32 %17, i32* %1
store i64 0, i64* @errno
%18 = load volatile double, double* %2
%19 = call i64 @log(double %18)
%20 = load i64, i64* @errno
%21 = icmp ne i64 0, %20
br i1 %21, label %22, label %23
22: ; preds = %14
br label %26
23: ; preds = %14
%24 = load i64, i64* @errno
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %24, i32 204)
br label %26
26: ; preds = %23, %22
%27 = phi i32 [ 0, %22 ], [ 1, %23 ]
%28 = load i32, i32* %1
%29 = add nsw i32 %28, %27
store i32 %29, i32* %1
store volatile double -1.000000e-03, double* %2
store i64 0, i64* @errno
%30 = load volatile double, double* %2
%31 = call i64 @sqrt(double %30)
%32 = load i64, i64* @errno
%33 = icmp ne i64 0, %32
br i1 %33, label %34, label %35
34: ; preds = %26
br label %38
35: ; preds = %26
%36 = load i64, i64* @errno
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64 %36, i32 206)
br label %38
38: ; preds = %35, %34
%39 = phi i32 [ 0, %34 ], [ 1, %35 ]
%40 = load i32, i32* %1
%41 = add nsw i32 %40, %39
store i32 %41, i32* %1
store volatile double 1.000100e+00, double* %2
store i64 0, i64* @errno
%42 = load volatile double, double* %2
%43 = call i64 @asin(double %42)
%44 = load i64, i64* @errno
%45 = icmp ne i64 0, %44
br i1 %45, label %46, label %47
46: ; preds = %38
br label %50
47: ; preds = %38
%48 = load i64, i64* @errno
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64 %48, i32 208)
br label %50
50: ; preds = %47, %46
%51 = phi i32 [ 0, %46 ], [ 1, %47 ]
%52 = load i32, i32* %1
%53 = add nsw i32 %52, %51
store i32 %53, i32* %1
store volatile double 0x3FEFF7CED916872B, double* %2
store i64 0, i64* @errno
%54 = load volatile double, double* %2
%55 = call i64 @acosh(double %54)
%56 = load i64, i64* @errno
%57 = icmp ne i64 0, %56
br i1 %57, label %58, label %59
58: ; preds = %50
br label %62
59: ; preds = %50
%60 = load i64, i64* @errno
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i64 %60, i32 218)
br label %62
62: ; preds = %59, %58
%63 = phi i32 [ 0, %58 ], [ 1, %59 ]
%64 = load i32, i32* %1
%65 = add nsw i32 %64, %63
store i32 %65, i32* %1
store volatile double 3.300000e+00, double* %2
store volatile double 0.000000e+00, double* %3
store i64 0, i64* @errno
%66 = load volatile double, double* %2
%67 = load volatile double, double* %3
%68 = call i64 @remainder(double %66, double %67)
%69 = load i64, i64* @errno
%70 = icmp ne i64 0, %69
br i1 %70, label %71, label %72
71: ; preds = %62
br label %75
72: ; preds = %62
%73 = load i64, i64* @errno
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i64 %73, i32 220)
br label %75
75: ; preds = %72, %71
%76 = phi i32 [ 0, %71 ], [ 1, %72 ]
%77 = load i32, i32* %1
%78 = add nsw i32 %77, %76
store i32 %78, i32* %1
%79 = load i32, i32* %1
ret i32 %79
}

LLVM IR (-O2):
@errno = global i64 0
@.str.1 = [29 x i8] c"%s - errno %d not set at %d\0A\00"
@.str.2 = [10 x i8] c"pow(x, y)\00"
@.str.3 = [7 x i8] c"log(x)\00"
@.str.4 = [8 x i8] c"sqrt(x)\00"
@.str.5 = [8 x i8] c"asin(x)\00"
@.str.6 = [9 x i8] c"acosh(x)\00"
@.str.7 = [16 x i8] c"remainder(x, y)\00"
@str = [46 x i8] c"Checking that exceptional lib calls set errno\00"
define i32 @test_exception() {
%1 = alloca double
%2 = alloca double
%3 = bitcast double* %1 to i8*
%4 = bitcast double* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
store volatile double -3.000000e+00, double* %1
store volatile double 4.400000e+00, double* %2
store i64 0, i64* @errno
%6 = load volatile double, double* %1
%7 = load volatile double, double* %2
%8 = tail call i64 @pow(double %6, double %7)
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = 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.2, i64 0, i64 0), i64 0, i32 203)
br label %13
13: ; preds = %0, %11
%14 = phi i32 [ 1, %11 ], [ 0, %0 ]
store i64 0, i64* @errno
%15 = load volatile double, double* %1
%16 = tail call i64 @log(double %15)
%17 = load i64, i64* @errno
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%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 ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 0, i32 204)
br label %21
21: ; preds = %13, %19
%22 = phi i32 [ 1, %19 ], [ 0, %13 ]
store volatile double -1.000000e-03, double* %1
store i64 0, i64* @errno
%23 = load volatile double, double* %1
%24 = tail call i64 @sqrt(double %23)
%25 = load i64, i64* @errno
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = 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 ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64 0, i32 206)
br label %29
29: ; preds = %21, %27
%30 = phi i32 [ 1, %27 ], [ 0, %21 ]
store volatile double 1.000100e+00, double* %1
store i64 0, i64* @errno
%31 = load volatile double, double* %1
%32 = tail call i64 @asin(double %31)
%33 = load i64, i64* @errno
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = 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 ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i64 0, i32 208)
br label %37
37: ; preds = %29, %35
%38 = phi i32 [ 1, %35 ], [ 0, %29 ]
store volatile double 0x3FEFF7CED916872B, double* %1
store i64 0, i64* @errno
%39 = load volatile double, double* %1
%40 = tail call i64 @acosh(double %39)
%41 = load i64, i64* @errno
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = 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 ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i64 0, i32 218)
br label %45
45: ; preds = %37, %43
%46 = phi i32 [ 1, %43 ], [ 0, %37 ]
store volatile double 3.300000e+00, double* %1
store volatile double 0.000000e+00, double* %2
store i64 0, i64* @errno
%47 = load volatile double, double* %1
%48 = load volatile double, double* %2
%49 = tail call i64 @remainder(double %47, double %48)
%50 = load i64, i64* @errno
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = 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 ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i64 0, i32 220)
br label %54
54: ; preds = %45, %52
%55 = phi i32 [ 1, %52 ], [ 0, %45 ]
%56 = add nuw nsw i32 %22, %14
%57 = add nuw nsw i32 %56, %30
%58 = add nuw nsw i32 %57, %38
%59 = add nuw nsw i32 %58, %46
%60 = add nuw nsw i32 %59, %55
ret i32 %60
}