#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 EMFILE 129
#define ENOENT 128
int /*<<< orphan*/ change_port(int);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ flush_addresses(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int fd;
  fd = open("/dev/mv88E6097F", 0);
  if (fd < 0) {
    printf("Can't open device file: %s\n", "/dev/mv88E6097F");
    switch (errno) {
    case EACCES:
      printf("Permission denied. Errno: %d\n", errno);
      break;
    case EMFILE:
      printf("No file handle available. Errno: %d\n", errno);
      break;
    case ENOENT:
      printf("File or path not found. Errno: %d\n", errno);
      break;
    default:
      printf("Unknown error. Errno: %d\n", errno);
      break;
    }
    exit(-1);
  }
  change_port(fd);
  flush_addresses(fd);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1256 <main+0xf6>
lea    0xe7f(%rip),%rdi
lea    0xe68(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
sub    $0x80,%eax
je     1219 <main+0xb9>
jmp    11bb <main+0x5b>
mov    -0x18(%rbp),%eax
sub    $0x81,%eax
je     11fd <main+0x9d>
jmp    11ce <main+0x6e>
mov    -0x18(%rbp),%eax
sub    $0x82,%eax
jne    1235 <main+0xd5>
jmp    11e1 <main+0x81>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124c <main+0xec>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124c <main+0xec>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124c <main+0xec>
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1030 <change_port@plt>
mov    -0x14(%rbp),%edi
call   1070 <flush_addresses@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe98(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
test   %eax,%eax
js     118e <main+0x2e>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <change_port@plt>
mov    %ebx,%edi
call   1070 <flush_addresses@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe7b(%rip),%rdi
lea    0xe64(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    -0x80(%rsi),%eax
cmp    $0x2,%eax
ja     11c6 <main+0x66>
cltq
lea    0xeef(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    11cd <main+0x6d>
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/mv88E6097F\00"
@.str.1 = [28 x i8] c"Can't open device file: %s\0A\00"
@errno = global i32 0
@.str.2 = [30 x i8] c"Permission denied. Errno: %d\0A\00"
@.str.3 = [37 x i8] c"No file handle available. Errno: %d\0A\00"
@.str.4 = [35 x i8] c"File or path not found. Errno: %d\0A\00"
@.str.5 = [26 x i8] c"Unknown error. Errno: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @errno
switch i32 %11, label %21 [
i32 130, label %12
i32 129, label %15
i32 128, label %18
]
12: ; preds = %9
%13 = load i32, i32* @errno
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %24
15: ; preds = %9
%16 = load i32, i32* @errno
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %16)
br label %24
18: ; preds = %9
%19 = load i32, i32* @errno
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %19)
br label %24
21: ; preds = %9
%22 = load i32, i32* @errno
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %18, %15, %12
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %2
%27 = load i32, i32* %5
%28 = call i32 @change_port(i32 %27)
%29 = load i32, i32* %5
%30 = call i32 @flush_addresses(i32 %29)
%31 = load i32, i32* %5
%32 = call i32 @close(i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/mv88E6097F\00"
@.str.1 = [28 x i8] c"Can't open device file: %s\0A\00"
@errno = global i32 0
@.str.2 = [30 x i8] c"Permission denied. Errno: %d\0A\00"
@.str.3 = [37 x i8] c"No file handle available. Errno: %d\0A\00"
@.str.4 = [35 x i8] c"File or path not found. Errno: %d\0A\00"
@.str.5 = [26 x i8] c"Unknown error. Errno: %d\0A\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([35 x i8]* @.str.4 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([37 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([30 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @errno
%8 = add i32 %7, -128
%9 = icmp ult i32 %8, 3
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = sext i32 %8 to i64
%12 = shl i64 %11, 2
%13 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %12)
br label %14
14: ; preds = %5, %10
%15 = phi i8* [ %13, %10 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), %5 ]
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %15, i32 %7)
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = tail call i32 @change_port(i32 %3)
%20 = tail call i32 @flush_addresses(i32 %3)
%21 = tail call i32 @close(i32 %3)
ret i32 0
}