#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_SUCCESS;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, double);
double sqrt(double);
int main(int argc, char **argv) {
  double d;
  d = sqrt((double)-1);
  if (errno) {
    perror("sqrt( - 1 ) failed ");
  } else {
    printf("sqrt( -1 ) = %f\n", d);
  }
  d = sqrt((double)2);
  if (errno) {
    perror("sqrt(2) failed ");
    errno = 0;
  } else {
    printf("sqrt(2) = %f\n", d);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xea2(%rip),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2e71(%rip),%rax
cmpq   $0x0,(%rax)
je     118a <main+0x4a>
lea    0xe90(%rip),%rdi
call   1040 <perror@plt>
jmp    119b <main+0x5b>
movsd  -0x18(%rbp),%xmm0
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe65(%rip),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2e2c(%rip),%rax
cmpq   $0x0,(%rax)
je     11dd <main+0x9d>
lea    0xe70(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e0f(%rip),%rax
movq   $0x0,(%rax)
jmp    11ee <main+0xae>
movsd  -0x18(%rbp),%xmm0
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
movsd  0xeb7(%rip),%xmm0
call   1050 <sqrt@plt>
mov    0x2e8b(%rip),%rbx
cmpq   $0x0,(%rbx)
je     118e <main+0x4e>
lea    0xeae(%rip),%rdi
call   1040 <perror@plt>
cmpq   $0x0,(%rbx)
je     11a0 <main+0x60>
lea    0xec1(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,(%rbx)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
cmpq   $0x0,(%rbx)
jne    116d <main+0x2d>
lea    0xe9e(%rip),%rdi
movsd  0xe59(%rip),%xmm0
call   1030 <printf@plt>
jmp    1180 <main+0x40>

LLVM IR (-O0):
@errno = global i64 0
@.str = [20 x i8] c"sqrt( - 1 ) failed \00"
@.str.1 = [17 x i8] c"sqrt( -1 ) = %f\0A\00"
@.str.2 = [16 x i8] c"sqrt(2) failed \00"
@.str.3 = [14 x i8] c"sqrt(2) = %f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call double @sqrt(double -1.000000e+00)
store double %7, double* %6
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %15
12: ; preds = %2
%13 = load double, double* %6
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), double %13)
br label %15
15: ; preds = %12, %10
%16 = call double @sqrt(double 2.000000e+00)
store double %16, double* %6
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* @errno
br label %24
21: ; preds = %15
%22 = load double, double* %6
%23 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %22)
br label %24
24: ; preds = %21, %19
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [20 x i8] c"sqrt( - 1 ) failed \00"
@.str.1 = [17 x i8] c"sqrt( -1 ) = %f\0A\00"
@.str.2 = [16 x i8] c"sqrt(2) failed \00"
@.str.3 = [14 x i8] c"sqrt(2) = %f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double @sqrt(double -1.000000e+00)
%4 = load i64, i64* @errno
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), double %3)
br label %10
10: ; preds = %8, %6
%11 = load i64, i64* @errno
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* @errno
br label %17
15: ; preds = %10
%16 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double 0x3FF6A09E667F3BCD)
br label %17
17: ; preds = %15, %13
%18 = load i32, i32* @EXIT_SUCCESS
%19 = tail call i32 @exit(i32 %18)
unreachable
}