#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
double sqrt(int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int main(int argc, char **argv) {
  double d;
  char *p;
  errno = 0;
  d = sqrt(-1);
  if (errno) {
    p = strerror(errno);
    fprintf(stderr, "sqrt(-1):%s\n", p);
  }
  errno = 0;
  d = sqrt(-2);
  if (errno) {
    perror("sqrt(-2) ");
  }
  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)
mov    0x2e6b(%rip),%rax
movq   $0x0,(%rax)
mov    $0xffffffff,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2e4e(%rip),%rax
cmpq   $0x0,(%rax)
je     11c0 <main+0x70>
mov    0x2e3d(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe45(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e11(%rip),%rax
movq   $0x0,(%rax)
mov    $0xfffffffe,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2df4(%rip),%rax
cmpq   $0x0,(%rax)
je     11fa <main+0xaa>
lea    0xe18(%rip),%rdi
call   1040 <perror@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rbx
movq   $0x0,(%rbx)
mov    $0xffffffff,%edi
call   1050 <sqrt@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     118e <main+0x3e>
call   1070 <strerror@plt>
mov    0x2e63(%rip),%rcx
mov    (%rcx),%edi
lea    0xe7a(%rip),%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
movq   $0x0,(%rbx)
mov    $0xfffffffe,%edi
call   1050 <sqrt@plt>
cmpq   $0x0,(%rbx)
je     11b1 <main+0x61>
lea    0xe61(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [13 x i8] c"sqrt(-1):%s\0A\00"
@.str.1 = [10 x i8] c"sqrt(-2) \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
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* @errno
%8 = call double @sqrt(i32 -1)
store double %8, double* %6
%9 = load i64, i64* @errno
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = call i8* @strerror(i64 %12)
store i8* %13, i8** %7
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %7
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %11, %2
store i64 0, i64* @errno
%18 = call double @sqrt(i32 -2)
store double %18, double* %6
%19 = load i64, i64* @errno
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* @EXIT_SUCCESS
%25 = call i32 @exit(i32 %24)
unreachable
}

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