#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EDOM;
int EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
double sqrt(int);
int main() {
  double val;
  FILE *f;
  val = sqrt(-1);
  if (errno == EDOM) {
    printf("invalid value\n");
  } else {
    printf("valid value\n");
  }
  errno = 0;
  val = sqrt(10);
  if (errno == EDOM) {
    printf("invalid value\n");
  } else {
    printf("valid value\n");
  }
  f = fopen("/tmp/nonfile", "r");
  if (!f) {
    printf("error number is %d\n", errno);
    perror("can't open file /tmp/nonfile");
  }
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xffffffff,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%rax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jne    118b <main+0x4b>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1199 <main+0x59>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e38(%rip),%rax
movq   $0x0,(%rax)
mov    $0xa,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%rax
jne    11e3 <main+0xa3>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f1 <main+0xb1>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3d(%rip),%rdi
lea    0xe10(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1237 <main+0xf7>
mov    0x2dbe(%rip),%rax
mov    (%rax),%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdf3(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%edi
call   1070 <sqrt@plt>
mov    0x2e6f(%rip),%r14
mov    (%r14),%rax
mov    0x2e75(%rip),%r15
cmp    (%r15),%rax
lea    0xeb6(%rip),%r12
lea    0xeb1(%rip),%rbx
mov    %rbx,%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
movq   $0x0,(%r14)
mov    $0xa,%edi
call   1070 <sqrt@plt>
mov    (%r14),%rax
cmp    (%r15),%rax
cmove  %r12,%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe6c(%rip),%rdi
lea    0xe3f(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11e0 <main+0x90>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%r14),%rsi
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe1e(%rip),%rdi
call   1060 <perror@plt>
jmp    11cb <main+0x7b>

LLVM IR (-O0):
@errno = global i64 0
@EDOM = global i64 0
@.str = [15 x i8] c"invalid value\0A\00"
@.str.1 = [13 x i8] c"valid value\0A\00"
@.str.2 = [13 x i8] c"/tmp/nonfile\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [20 x i8] c"error number is %d\0A\00"
@.str.5 = [29 x i8] c"can't open file /tmp/nonfile\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i32*
store i32 0, i32* %1
%4 = call double @sqrt(i32 -1)
store double %4, double* %2
%5 = load i64, i64* @errno
%6 = load i64, i64* @EDOM
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
store i64 0, i64* @errno
%13 = call double @sqrt(i32 10)
store double %13, double* %2
%14 = load i64, i64* @errno
%15 = load i64, i64* @EDOM
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %21
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
%22 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %22, i32** %3
%23 = load i32*, i32** %3
%24 = icmp ne i32* %23, null
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i64 %26)
%28 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %29
29: ; preds = %25, %21
%30 = load i32, i32* @EXIT_FAILURE
ret i32 %30
}

LLVM IR (-O2):
@errno = global i64 0
@EDOM = global i64 0
@.str.2 = [13 x i8] c"/tmp/nonfile\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [20 x i8] c"error number is %d\0A\00"
@.str.5 = [29 x i8] c"can't open file /tmp/nonfile\00"
@EXIT_FAILURE = global i32 0
@str.6 = [12 x i8] c"valid value\00"
@str.8 = [14 x i8] c"invalid value\00"
define i32 @main() {
%1 = tail call double @sqrt(i32 -1)
%2 = load i64, i64* @errno
%3 = load i64, i64* @EDOM
%4 = icmp eq i64 %2, %3
%5 = select i1 %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
store i64 0, i64* @errno
%7 = tail call double @sqrt(i32 10)
%8 = load i64, i64* @errno
%9 = load i64, i64* @EDOM
%10 = icmp eq i64 %8, %9
%11 = select i1 %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0)
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = load i64, i64* @errno
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i64 %16)
%18 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %19
19: ; preds = %15, %0
%20 = load i32, i32* @EXIT_FAILURE
ret i32 %20
}