#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 */
int EDOM;
int ERANGE;
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
double log(double);
int /*<<< orphan*/ printf(char *, ...);
double sqrt(int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main() {
  FILE *fp;
  fp = fopen("file.txt", "r");
  if (fp == NULL) {
    fprintf(stderr, "Value of errno: %d\n", errno);
    fprintf(stderr, "Error opening file: %s\n", strerror(errno));
  } else {
    fclose(fp);
  }
  double val;
  errno = 0;
  val = sqrt(-10);
  if (errno == EDOM) {
    printf("Invalid value \n");
  } else {
    printf("Valid value\n");
  }
  printf("%f\n", val);
  errno = 0;
  val = sqrt(10);
  if (errno == EDOM) {
    printf("Invalid value\n");
  } else {
    printf("Valid value\n");
  }
  double x;
  double value;
  x = 2.000000;
  value = log(x);
  if (errno == ERANGE) {
    printf("Log(%f) is out of range\n", x);
  } else {
    printf("Log(%f) = %f\n", x, value);
  }
  x = 1.000000;
  value = log(x);
  if (errno == ERANGE) {
    printf("Log(%f) is out of range\n", x);
  } else {
    printf("Log(%f) = %f\n", x, value);
  }
  x = 0.000000;
  value = log(x);
  if (errno == ERANGE) {
    printf("Log(%f) is out of range\n", x);
  } else {
    printf("Log(%f) = %f\n", x, value);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f4 <main+0x84>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11fd <main+0x8d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2dc4(%rip),%rax
movl   $0x0,(%rax)
mov    $0xfffffff6,%edi
call   1080 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    0x2dbf(%rip),%rcx
cmp    (%rcx),%eax
jne    1244 <main+0xd4>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1252 <main+0xe2>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe38(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2d5c(%rip),%rax
movl   $0x0,(%rax)
mov    $0xa,%edi
call   1080 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    0x2d57(%rip),%rcx
cmp    (%rcx),%eax
jne    12ac <main+0x13c>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ba <main+0x14a>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  0xd3e(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x28(%rbp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
mov    0x2cfa(%rip),%rcx
cmp    (%rcx),%eax
jne    1306 <main+0x196>
movsd  -0x20(%rbp),%xmm0
lea    0xd79(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    131e <main+0x1ae>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xd75(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  0xce2(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x28(%rbp)
mov    0x2c87(%rip),%rax
mov    (%rax),%eax
mov    0x2c96(%rip),%rcx
cmp    (%rcx),%eax
jne    136a <main+0x1fa>
movsd  -0x20(%rbp),%xmm0
lea    0xd15(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1382 <main+0x212>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xd11(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x28(%rbp)
mov    0x2c28(%rip),%rax
mov    (%rax),%eax
mov    0x2c37(%rip),%rcx
cmp    (%rcx),%eax
jne    13c9 <main+0x259>
movsd  -0x20(%rbp),%xmm0
lea    0xcb6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    13e1 <main+0x271>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xcb2(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe88(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ab <main+0x2b>
mov    %rax,%rdi
call   1040 <fclose@plt>
jmp    11e9 <main+0x69>
mov    0x2e1e(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e0d(%rip),%r14
mov    (%r14),%edx
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%ebx
mov    (%r14),%edi
call   10a0 <strerror@plt>
lea    0xe5a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2dd8(%rip),%rbx
movl   $0x0,(%rbx)
mov    $0xfffffff6,%edi
call   1090 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
mov    (%rbx),%eax
mov    0x2dd9(%rip),%r14
cmp    (%r14),%eax
lea    0xe77(%rip),%rdi
lea    0xe56(%rip),%r15
cmovne %r15,%rdi
call   1030 <puts@plt>
lea    0xe42(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0x0,(%rbx)
mov    $0xa,%edi
call   1090 <sqrt@plt>
mov    (%rbx),%eax
cmp    (%r14),%eax
lea    0xe29(%rip),%rdi
cmovne %r15,%rdi
call   1030 <puts@plt>
mov    (%rbx),%eax
mov    0x2d75(%rip),%r14
cmp    (%r14),%eax
jne    1288 <main+0x108>
lea    0xdd8(%rip),%rdi
movsd  0xd81(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12a6 <main+0x126>
lea    0xdd9(%rip),%rdi
movsd  0xd69(%rip),%xmm0
movsd  0xd69(%rip),%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
mov    (%rbx),%eax
cmp    (%r14),%eax
jne    12c5 <main+0x145>
lea    0xd9b(%rip),%rdi
movsd  0xd54(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12de <main+0x15e>
lea    0xd9c(%rip),%rdi
movsd  0xd3c(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
call   1070 <log@plt>
mov    (%rbx),%eax
cmp    (%r14),%eax
jne    1300 <main+0x180>
lea    0xd5b(%rip),%rdi
xorps  %xmm0,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
jmp    1314 <main+0x194>
movaps %xmm0,%xmm1
lea    0xd5e(%rip),%rdi
xorps  %xmm0,%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"Value of errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [24 x i8] c"Error opening file: %s\0A\00"
@EDOM = global i32 0
@.str.4 = [16 x i8] c"Invalid value \0A\00"
@.str.5 = [13 x i8] c"Valid value\0A\00"
@.str.6 = [4 x i8] c"%f\0A\00"
@.str.7 = [15 x i8] c"Invalid value\0A\00"
@ERANGE = global i32 0
@.str.8 = [25 x i8] c"Log(%f) is out of range\0A\00"
@.str.9 = [14 x i8] c"Log(%f) = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca double
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %20
17: ; preds = %0
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %17, %9
store i32 0, i32* @errno
%21 = call double @sqrt(i32 -10)
store double %21, double* %3
%22 = load i32, i32* @errno
%23 = load i32, i32* @EDOM
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %29
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %29
29: ; preds = %27, %25
%30 = load double, double* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %30)
store i32 0, i32* @errno
%32 = call double @sqrt(i32 10)
store double %32, double* %3
%33 = load i32, i32* @errno
%34 = load i32, i32* @EDOM
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %40
38: ; preds = %29
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %40
40: ; preds = %38, %36
store double 2.000000e+00, double* %4
%41 = load double, double* %4
%42 = call double @log(double %41)
store double %42, double* %5
%43 = load i32, i32* @errno
%44 = load i32, i32* @ERANGE
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load double, double* %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double %47)
br label %53
49: ; preds = %40
%50 = load double, double* %4
%51 = load double, double* %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), double %50, double %51)
br label %53
53: ; preds = %49, %46
store double 1.000000e+00, double* %4
%54 = load double, double* %4
%55 = call double @log(double %54)
store double %55, double* %5
%56 = load i32, i32* @errno
%57 = load i32, i32* @ERANGE
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = load double, double* %4
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double %60)
br label %66
62: ; preds = %53
%63 = load double, double* %4
%64 = load double, double* %5
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), double %63, double %64)
br label %66
66: ; preds = %62, %59
store double 0.000000e+00, double* %4
%67 = load double, double* %4
%68 = call double @log(double %67)
store double %68, double* %5
%69 = load i32, i32* @errno
%70 = load i32, i32* @ERANGE
%71 = icmp eq i32 %69, %70
br i1 %71, label %72, label %75
72: ; preds = %66
%73 = load double, double* %4
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double %73)
br label %79
75: ; preds = %66
%76 = load double, double* %4
%77 = load double, double* %5
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), double %76, double %77)
br label %79
79: ; preds = %75, %72
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"Value of errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [24 x i8] c"Error opening file: %s\0A\00"
@EDOM = global i32 0
@.str.6 = [4 x i8] c"%f\0A\00"
@ERANGE = global i32 0
@.str.8 = [25 x i8] c"Log(%f) is out of range\0A\00"
@.str.9 = [14 x i8] c"Log(%f) = %f\0A\00"
@str.10 = [12 x i8] c"Valid value\00"
@str.11 = [14 x i8] c"Invalid value\00"
@str.12 = [15 x i8] c"Invalid value \00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %11
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = load i32, i32* @errno
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %9)
br label %13
11: ; preds = %0
%12 = tail call i32 @fclose(i32* %1)
br label %13
13: ; preds = %11, %3
store i32 0, i32* @errno
%14 = tail call double @sqrt(i32 -10)
%15 = load i32, i32* @errno
%16 = load i32, i32* @EDOM
%17 = icmp eq i32 %15, %16
%18 = select i1 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0)
%19 = tail call i32 @puts(i8* dereferenceable(1) %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double %14)
store i32 0, i32* @errno
%21 = tail call double @sqrt(i32 10)
%22 = load i32, i32* @errno
%23 = load i32, i32* @EDOM
%24 = icmp eq i32 %22, %23
%25 = select i1 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0)
%26 = tail call i32 @puts(i8* dereferenceable(1) %25)
%27 = load i32, i32* @errno
%28 = load i32, i32* @ERANGE
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %13
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double 2.000000e+00)
br label %34
32: ; preds = %13
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), double 2.000000e+00, double 0x3FE62E42FEFA39EF)
br label %34
34: ; preds = %32, %30
%35 = load i32, i32* @errno
%36 = load i32, i32* @ERANGE
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double 1.000000e+00)
br label %42
40: ; preds = %34
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), double 1.000000e+00, double 0.000000e+00)
br label %42
42: ; preds = %40, %38
%43 = tail call double @log(double 0.000000e+00)
%44 = load i32, i32* @errno
%45 = load i32, i32* @ERANGE
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), double 0.000000e+00)
br label %51
49: ; preds = %42
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), double 0.000000e+00, double %43)
br label %51
51: ; preds = %49, %47
ret i32 0
}