#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 */
#define EACCES 130
#define ENOENT 129
#define ENOTDIR 128
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void errno_msg(char *filename) {
  fprintf(stderr, "Error opening file: %s\n", filename);
  switch (errno) {
  case EACCES:
    fprintf(stderr, "Permission denied\n");
    break;
  case ENOENT:
    fprintf(stderr, "No such file\n");
    break;
  case ENOTDIR:
    fprintf(stderr, "Not a directory\n");
    break;
  default:
    fprintf(stderr, "Something went wrong and I don't know what\n");
  }
}


x86 assembly (clang, -O0):
<errno_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xed0(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
sub    $0x80,%eax
je     11b1 <errno_msg+0xa1>
jmp    1153 <errno_msg+0x43>
mov    -0xc(%rbp),%eax
sub    $0x81,%eax
je     1195 <errno_msg+0x85>
jmp    1166 <errno_msg+0x56>
mov    -0xc(%rbp),%eax
sub    $0x82,%eax
jne    11cd <errno_msg+0xbd>
jmp    1179 <errno_msg+0x69>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e4 <errno_msg+0xd4>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e4 <errno_msg+0xd4>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e4 <errno_msg+0xd4>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<errno_msg>:
push   %rbx
mov    %rdi,%rdx
mov    0x2ec5(%rip),%rbx
mov    (%rbx),%edi
lea    0xedc(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
cmp    $0x2,%eax
ja     114e <errno_msg+0x3e>
cltq
lea    0xf33(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    1155 <errno_msg+0x45>
lea    0xef5(%rip),%rsi
mov    (%rbx),%edi
xor    %eax,%eax
pop    %rbx
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Error opening file: %s\0A\00"
@errno = global i32 0
@.str.1 = [19 x i8] c"Permission denied\0A\00"
@.str.2 = [14 x i8] c"No such file\0A\00"
@.str.3 = [17 x i8] c"Not a directory\0A\00"
@.str.4 = [44 x i8] c"Something went wrong and I don't know what\0A\00"
define void @errno_msg(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i32, i32* @stderr
%4 = load i8*, i8** %2
%5 = call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i32, i32* @errno
switch i32 %6, label %16 [
i32 130, label %7
i32 129, label %10
i32 128, label %13
]
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %19
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %19
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %19
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %16, %13, %10, %7
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Error opening file: %s\0A\00"
@errno = global i32 0
@.str.1 = [19 x i8] c"Permission denied\0A\00"
@.str.2 = [14 x i8] c"No such file\0A\00"
@.str.3 = [17 x i8] c"Not a directory\0A\00"
@.str.4 = [44 x i8] c"Something went wrong and I don't know what\0A\00"
@reltable.errno_msg = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.errno_msg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.errno_msg to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.errno_msg to i64)) to i32)]
define void @errno_msg(i8* %0) {
%2 = load i32, i32* @stderr
%3 = tail call i32 (i32, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = load i32, i32* @errno
%5 = add i32 %4, -128
%6 = icmp ult i32 %5, 3
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = sext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.errno_msg to i8*), i64 %9)
br label %11
11: ; preds = %1, %7
%12 = phi i8* [ %10, %7 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), %1 ]
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* %12)
ret void
}