#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 */
scalar_t__ EACCES;
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ ft_puterr(char *);
int /*<<< orphan*/ write(int, char *, int);
int on_error(char *arg) {
  ft_puterr("cat: ");
  ft_puterr(arg);
  if (errno == ENOENT)
    write(2, ": No such file or directory\n", 28);
  else if (errno == EACCES)
    write(2, ": Permission denied\n", 20);
  else
    write(2, ": open() error\n", 15);
  return (1);
}


x86 assembly (clang, -O0):
<on_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
call   1040 <ft_puterr@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ft_puterr@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%rax
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%rax
jne    1176 <on_error+0x56>
mov    $0x2,%edi
lea    0xe9f(%rip),%rsi
mov    $0x1c,%edx
call   1030 <write@plt>
jmp    11c6 <on_error+0xa6>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
jne    11ab <on_error+0x8b>
mov    $0x2,%edi
lea    0xe87(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
jmp    11c1 <on_error+0xa1>
mov    $0x2,%edi
lea    0xe81(%rip),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
jmp    11c6 <on_error+0xa6>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<on_error>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rdi
call   1040 <ft_puterr@plt>
mov    %rbx,%rdi
call   1040 <ft_puterr@plt>
mov    0x2e99(%rip),%rax
mov    (%rax),%rax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%rax
jne    1161 <on_error+0x41>
lea    0xeb1(%rip),%rsi
mov    $0x2,%edi
mov    $0x1c,%edx
jmp    1191 <on_error+0x71>
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
jne    1180 <on_error+0x60>
lea    0xeaf(%rip),%rsi
mov    $0x2,%edi
mov    $0x14,%edx
jmp    1191 <on_error+0x71>
lea    0xeb1(%rip),%rsi
mov    $0x2,%edi
mov    $0xf,%edx
call   1030 <write@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"cat: \00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [29 x i8] c": No such file or directory\0A\00"
@EACCES = global i64 0
@.str.2 = [21 x i8] c": Permission denied\0A\00"
@.str.3 = [16 x i8] c": open() error\0A\00"
define i32 @on_error(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 @ft_puterr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = load i8*, i8** %2
%5 = call i32 @ft_puterr(i8* %4)
%6 = load i64, i64* @errno
%7 = load i64, i64* @ENOENT
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @write(i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 28)
br label %20
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = load i64, i64* @EACCES
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @write(i32 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 20)
br label %19
17: ; preds = %11
%18 = call i32 @write(i32 2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 15)
br label %19
19: ; preds = %17, %15
br label %20
20: ; preds = %19, %9
ret i32 1
}

LLVM IR (-O2):
@.str = [6 x i8] c"cat: \00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [29 x i8] c": No such file or directory\0A\00"
@EACCES = global i64 0
@.str.2 = [21 x i8] c": Permission denied\0A\00"
@.str.3 = [16 x i8] c": open() error\0A\00"
define i32 @on_error(i8* %0) {
%2 = tail call i32 @ft_puterr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @ft_puterr(i8* %0)
%4 = load i64, i64* @errno
%5 = load i64, i64* @ENOENT
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 28)
br label %16
9: ; preds = %1
%10 = load i64, i64* @EACCES
%11 = icmp eq i64 %4, %10
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 20)
br label %16
14: ; preds = %9
%15 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 15)
br label %16
16: ; preds = %12, %14, %7
ret i32 1
}