#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(void) {
  int fd, my_err;
  errno = 0;
  if ((fd = open("probably/this/file/doesnt/exist", O_RDONLY)) < 0) {
    my_err = errno;
    if (my_err != 0) {
      fprintf(stderr, "Err.:(%d) Il file non esiste\n", errno);
      exit(my_err);
    }
    exit(EXIT_FAILURE);
  }
  close(fd);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
movl   $0x0,(%rax)
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11c7 <main+0x87>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b9 <main+0x79>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%edi
call   1060 <exit@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e88(%rip),%rbx
movl   $0x0,(%rbx)
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
lea    0xea2(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1179 <main+0x39>
mov    %eax,%edi
call   1030 <close@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    (%rbx),%ebx
test   %ebx,%ebx
jne    118d <main+0x4d>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [32 x i8] c"probably/this/file/doesnt/exist\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Err.:(%d) Il file non esiste\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* @errno
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %0
%8 = load i32, i32* @errno
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %7
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %0
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [32 x i8] c"probably/this/file/doesnt/exist\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Err.:(%d) Il file non esiste\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
store i32 0, i32* @errno
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %0
%5 = load i32, i32* @errno
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%10 = tail call i32 @exit(i32 %5)
unreachable
11: ; preds = %4
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = tail call i32 @close(i32 %2)
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}