#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 u_int8_t;
typedef int /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ config_space;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int PATH_MAX;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int get_port_type(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int write(int, int *, int);
void config_card(char *dev_path, int ports) {
  char *input = NULL;
  size_t len = 0;
  ssize_t read;
  char config_path[PATH_MAX];
  u_int8_t port_config;
  u_int8_t config_space[4] = {0};
  int i;
  int config_fd;
  for (i = 0; i < ports; i++) {
    port_config = get_port_type(i);
    if (ports == 8) {
      switch (i) {
      case 0:
        config_space[0] = (config_space[0] & 0xff00) | port_config;
        break;
      case 1:
        config_space[0] = port_config << 4 | (config_space[0] & 0xff);
        break;
      case 2:
        config_space[1] = port_config << 4 | (config_space[1] & 0xff);
        break;
      case 3:
        config_space[1] = (config_space[1] & 0xff00) | port_config;
        break;
      case 4:
        config_space[2] = (config_space[0] & 0xff00) | port_config;
        break;
      case 5:
        config_space[2] = port_config << 4 | (config_space[2] & 0xff);
        break;
      case 6:
        config_space[3] = (config_space[3] & 0xff00) | port_config;
        break;
      case 7:
        config_space[3] = port_config << 4 | (config_space[3] & 0xff);
        break;
      default:
        printf("default fault:%d\n", 418);
        break;
      }
    } else {
      switch (i) {
      case 0:
        config_space[0] |= (config_space[0] & 0xff00) | port_config;
        break;
      case 1:
        config_space[0] |= port_config << 4 | (config_space[0] & 0xff);
        break;
      case 2:
        config_space[1] |= (config_space[1] & 0xff00) | port_config;
        break;
      case 3:
        config_space[3] |= port_config << 4 | (config_space[3] & 0xff);
        break;
      default:
        printf("default fault:%d\n", 439);
        break;
      }
    }
  }
  strcpy(config_path, dev_path);
  strcat(config_path, "/config");
  config_fd = open(config_path, O_RDWR);
  if (config_fd < 0) {
    printf("error opening config file: %s\n", strerror(errno));
    return;
  }
  if (lseek(config_fd, 0xb4, SEEK_SET) == -1) {
    printf("error calling lseek: %s\n", strerror(errno));
    return;
  }
  if (write(config_fd, config_space, sizeof(config_space)) == -1) {
    printf("error writing to config: %s\n", strerror(errno));
    return;
  }
  close(config_fd);
}


x86 assembly (clang, -O0):
<config_card>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13c7 <config_card+0x227>
mov    -0x54(%rbp),%edi
call   1090 <get_port_type@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x8,-0xc(%rbp)
jne    1313 <config_card+0x173>
mov    -0x54(%rbp),%eax
mov    %rax,-0x70(%rbp)
sub    $0x7,%rax
ja     12fb <config_card+0x15b>
mov    -0x70(%rbp),%rax
lea    0xdce(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x50(%rbp),%eax
and    $0xff00,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x50(%rbp)
jmp    130e <config_card+0x16e>
mov    -0x3c(%rbp),%eax
shl    $0x4,%eax
mov    -0x50(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %eax,-0x50(%rbp)
jmp    130e <config_card+0x16e>
mov    -0x3c(%rbp),%eax
shl    $0x4,%eax
mov    -0x4c(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %eax,-0x4c(%rbp)
jmp    130e <config_card+0x16e>
mov    -0x4c(%rbp),%eax
and    $0xff00,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    130e <config_card+0x16e>
mov    -0x50(%rbp),%eax
and    $0xff00,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    130e <config_card+0x16e>
mov    -0x3c(%rbp),%eax
shl    $0x4,%eax
mov    -0x48(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %eax,-0x48(%rbp)
jmp    130e <config_card+0x16e>
mov    -0x44(%rbp),%eax
and    $0xff00,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    130e <config_card+0x16e>
mov    -0x3c(%rbp),%eax
shl    $0x4,%eax
mov    -0x44(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %eax,-0x44(%rbp)
jmp    130e <config_card+0x16e>
lea    0xd2e(%rip),%rdi
mov    $0x1a2,%esi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13b4 <config_card+0x214>
mov    -0x54(%rbp),%eax
mov    %rax,-0x78(%rbp)
sub    $0x3,%rax
ja     139c <config_card+0x1fc>
mov    -0x78(%rbp),%rax
lea    0xcd1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x50(%rbp),%eax
and    $0xff00,%eax
or     -0x3c(%rbp),%eax
or     -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
jmp    13af <config_card+0x20f>
mov    -0x3c(%rbp),%eax
shl    $0x4,%eax
mov    -0x50(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
or     -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
jmp    13af <config_card+0x20f>
mov    -0x4c(%rbp),%eax
and    $0xff00,%eax
or     -0x3c(%rbp),%eax
or     -0x4c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    13af <config_card+0x20f>
mov    -0x3c(%rbp),%eax
shl    $0x4,%eax
mov    -0x44(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
or     -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    13af <config_card+0x20f>
lea    0xc8d(%rip),%rdi
mov    $0x1b7,%esi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13b4 <config_card+0x214>
jmp    13b9 <config_card+0x219>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1205 <config_card+0x65>
mov    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x68(%rbp),%rdi
lea    0xc63(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x68(%rbp),%rdi
mov    0x2bf1(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    142e <config_card+0x28e>
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xc2f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x5c(%rbp)
jmp    14cc <config_card+0x32c>
mov    -0x58(%rbp),%edi
mov    0x2b90(%rip),%rax
mov    (%rax),%edx
mov    $0xb4,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1478 <config_card+0x2d8>
mov    0x2b7c(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xc04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x5c(%rbp)
jmp    14cc <config_card+0x32c>
mov    -0x58(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    14bd <config_card+0x31d>
mov    0x2b37(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xbd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x5c(%rbp)
jmp    14cc <config_card+0x32c>
mov    -0x58(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_card>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r13d
mov    %rdi,%rsi
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,-0x40(%rbp)
test   %r13d,%r13d
jle    12fa <config_card+0x16a>
mov    %rsi,-0x48(%rbp)
mov    %rbx,-0x50(%rbp)
movl   $0x0,-0x2c(%rbp)
xor    %r12d,%r12d
xor    %r14d,%r14d
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    11ff <config_card+0x6f>
shl    $0x4,%eax
or     %eax,%r15d
add    $0x1,%ebx
cmp    %ebx,%r13d
je     12e0 <config_card+0x150>
mov    %ebx,%edi
call   1080 <get_port_type@plt>
mov    %ebx,%ecx
cmp    $0x8,%r13d
jne    1230 <config_card+0xa0>
cmp    $0x7,%ebx
ja     1265 <config_card+0xd5>
lea    0xdf6(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
and    $0xff00,%r12d
or     %eax,%r12d
jmp    11f3 <config_card+0x63>
nop
cmp    $0x3,%ebx
ja     124a <config_card+0xba>
lea    0xdc4(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
or     %eax,%r12d
jmp    11f3 <config_card+0x63>
lea    0xddf(%rip),%rdi
mov    $0x1b7,%esi
jmp    1271 <config_card+0xe1>
shl    $0x4,%eax
or     %eax,%r12d
jmp    11f3 <config_card+0x63>
or     %eax,%r14d
jmp    11f3 <config_card+0x63>
lea    0xdc4(%rip),%rdi
mov    $0x1a2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f3 <config_card+0x63>
shl    $0x4,%eax
movzbl %r12b,%r12d
or     %eax,%r12d
jmp    11f3 <config_card+0x63>
shl    $0x4,%eax
movzbl %r14b,%r14d
or     %eax,%r14d
jmp    11f3 <config_card+0x63>
and    $0xff00,%r14d
or     %eax,%r14d
jmp    11f3 <config_card+0x63>
mov    %r12d,%ecx
and    $0xff00,%ecx
jmp    12be <config_card+0x12e>
shl    $0x4,%eax
mov    -0x2c(%rbp),%ecx
movzbl %cl,%ecx
or     %eax,%ecx
mov    %ecx,-0x2c(%rbp)
jmp    11f3 <config_card+0x63>
and    $0xff00,%r15d
jmp    11f0 <config_card+0x60>
shl    $0x4,%eax
movzbl %r15b,%r15d
jmp    11f0 <config_card+0x60>
mov    %r15d,-0x34(%rbp)
mov    %r14d,-0x3c(%rbp)
mov    %r12d,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x50(%rbp),%rbx
mov    -0x48(%rbp),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xd39(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1360 <config_card+0x1d0>
mov    %eax,%ebx
mov    0x2c99(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xb4,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     1377 <config_card+0x1e7>
lea    -0x40(%rbp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     138e <config_card+0x1fe>
mov    %ebx,%edi
call   1070 <close@plt>
jmp    13ad <config_card+0x21d>
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcd5(%rip),%rdi
jmp    13a3 <config_card+0x213>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcdd(%rip),%rdi
jmp    13a3 <config_card+0x213>
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcdf(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [18 x i8] c"default fault:%d\0A\00"
@.str.1 = [8 x i8] c"/config\00"
@O_RDWR = global i32 0
@.str.2 = [31 x i8] c"error opening config file: %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [25 x i8] c"error calling lseek: %s\0A\00"
@.str.4 = [29 x i8] c"error writing to config: %s\0A\00"
define void @config_card(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca [4 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %5
store i64 0, i64* %6
%15 = load i32, i32* @PATH_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = bitcast [4 x i32]* %11 to i8*
store i32 0, i32* %12
br label %20
20: ; preds = %138, %2
%21 = load i32, i32* %12
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %141
24: ; preds = %20
%25 = load i32, i32* %12
%26 = call i32 @get_port_type(i32 %25)
store i32 %26, i32* %10
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 8
br i1 %28, label %29, label %94
29: ; preds = %24
%30 = load i32, i32* %12
switch i32 %30, label %91 [
i32 0, label %31
i32 1, label %38
i32 2, label %46
i32 3, label %54
i32 4, label %61
i32 5, label %68
i32 6, label %76
i32 7, label %83
]
31: ; preds = %29
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%33 = load i32, i32* %32
%34 = and i32 %33, 65280
%35 = load i32, i32* %10
%36 = or i32 %34, %35
%37 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
store i32 %36, i32* %37
br label %93
38: ; preds = %29
%39 = load i32, i32* %10
%40 = shl i32 %39, 4
%41 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%42 = load i32, i32* %41
%43 = and i32 %42, 255
%44 = or i32 %40, %43
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
store i32 %44, i32* %45
br label %93
46: ; preds = %29
%47 = load i32, i32* %10
%48 = shl i32 %47, 4
%49 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
%50 = load i32, i32* %49
%51 = and i32 %50, 255
%52 = or i32 %48, %51
%53 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
store i32 %52, i32* %53
br label %93
54: ; preds = %29
%55 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
%56 = load i32, i32* %55
%57 = and i32 %56, 65280
%58 = load i32, i32* %10
%59 = or i32 %57, %58
%60 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
store i32 %59, i32* %60
br label %93
61: ; preds = %29
%62 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%63 = load i32, i32* %62
%64 = and i32 %63, 65280
%65 = load i32, i32* %10
%66 = or i32 %64, %65
%67 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 2
store i32 %66, i32* %67
br label %93
68: ; preds = %29
%69 = load i32, i32* %10
%70 = shl i32 %69, 4
%71 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 2
%72 = load i32, i32* %71
%73 = and i32 %72, 255
%74 = or i32 %70, %73
%75 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 2
store i32 %74, i32* %75
br label %93
76: ; preds = %29
%77 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
%78 = load i32, i32* %77
%79 = and i32 %78, 65280
%80 = load i32, i32* %10
%81 = or i32 %79, %80
%82 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
store i32 %81, i32* %82
br label %93
83: ; preds = %29
%84 = load i32, i32* %10
%85 = shl i32 %84, 4
%86 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
%87 = load i32, i32* %86
%88 = and i32 %87, 255
%89 = or i32 %85, %88
%90 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
store i32 %89, i32* %90
br label %93
91: ; preds = %29
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 418)
br label %93
93: ; preds = %91, %83, %76, %68, %61, %54, %46, %38, %31
br label %137
94: ; preds = %24
%95 = load i32, i32* %12
switch i32 %95, label %134 [
i32 0, label %96
i32 1, label %105
i32 2, label %115
i32 3, label %124
]
96: ; preds = %94
%97 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%98 = load i32, i32* %97
%99 = and i32 %98, 65280
%100 = load i32, i32* %10
%101 = or i32 %99, %100
%102 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%103 = load i32, i32* %102
%104 = or i32 %103, %101
store i32 %104, i32* %102
br label %136
105: ; preds = %94
%106 = load i32, i32* %10
%107 = shl i32 %106, 4
%108 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%109 = load i32, i32* %108
%110 = and i32 %109, 255
%111 = or i32 %107, %110
%112 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%113 = load i32, i32* %112
%114 = or i32 %113, %111
store i32 %114, i32* %112
br label %136
115: ; preds = %94
%116 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
%117 = load i32, i32* %116
%118 = and i32 %117, 65280
%119 = load i32, i32* %10
%120 = or i32 %118, %119
%121 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
%122 = load i32, i32* %121
%123 = or i32 %122, %120
store i32 %123, i32* %121
br label %136
124: ; preds = %94
%125 = load i32, i32* %10
%126 = shl i32 %125, 4
%127 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
%128 = load i32, i32* %127
%129 = and i32 %128, 255
%130 = or i32 %126, %129
%131 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
%132 = load i32, i32* %131
%133 = or i32 %132, %130
store i32 %133, i32* %131
br label %136
134: ; preds = %94
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 439)
br label %136
136: ; preds = %134, %124, %115, %105, %96
br label %137
137: ; preds = %136, %93
br label %138
138: ; preds = %137
%139 = load i32, i32* %12
%140 = add nsw i32 %139, 1
store i32 %140, i32* %12
br label %20
141: ; preds = %20
%142 = load i8*, i8** %3
%143 = call i32 @strcpy(i8* %18, i8* %142)
%144 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%145 = load i32, i32* @O_RDWR
%146 = call i32 @open(i8* %18, i32 %145)
store i32 %146, i32* %13
%147 = load i32, i32* %13
%148 = icmp slt i32 %147, 0
br i1 %148, label %149, label %153
149: ; preds = %141
%150 = load i32, i32* @errno
%151 = call i8* @strerror(i32 %150)
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %151)
store i32 1, i32* %14
br label %174
153: ; preds = %141
%154 = load i32, i32* %13
%155 = load i32, i32* @SEEK_SET
%156 = call i32 @lseek(i32 %154, i32 180, i32 %155)
%157 = icmp eq i32 %156, -1
br i1 %157, label %158, label %162
158: ; preds = %153
%159 = load i32, i32* @errno
%160 = call i8* @strerror(i32 %159)
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %160)
store i32 1, i32* %14
br label %174
162: ; preds = %153
%163 = load i32, i32* %13
%164 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%165 = call i32 @write(i32 %163, i32* %164, i32 16)
%166 = icmp eq i32 %165, -1
br i1 %166, label %167, label %171
167: ; preds = %162
%168 = load i32, i32* @errno
%169 = call i8* @strerror(i32 %168)
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %169)
store i32 1, i32* %14
br label %174
171: ; preds = %162
%172 = load i32, i32* %13
%173 = call i32 @close(i32 %172)
store i32 0, i32* %14
br label %174
174: ; preds = %171, %167, %158, %149
%175 = load i8*, i8** %8
%176 = load i32, i32* %14
switch i32 %176, label %178 [
i32 0, label %177
i32 1, label %177
]
177: ; preds = %174, %174
ret void
178: ; preds = %174
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [18 x i8] c"default fault:%d\0A\00"
@.str.1 = [8 x i8] c"/config\00"
@O_RDWR = global i32 0
@.str.2 = [31 x i8] c"error opening config file: %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [25 x i8] c"error calling lseek: %s\0A\00"
@.str.4 = [29 x i8] c"error writing to config: %s\0A\00"
define void @config_card(i8* %0, i32 %1) {
%3 = alloca [4 x i32]
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast [4 x i32]* %3 to i8*
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %74
9: ; preds = %2
%10 = icmp eq i32 %1, 8
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
br label %15
15: ; preds = %9, %66
%16 = phi i32 [ 0, %9 ], [ %67, %66 ]
%17 = phi i32 [ 0, %9 ], [ %68, %66 ]
%18 = phi i32 [ 0, %9 ], [ %69, %66 ]
%19 = phi i32 [ 0, %9 ], [ %70, %66 ]
%20 = phi i32 [ 0, %9 ], [ %71, %66 ]
%21 = tail call i32 @get_port_type(i32 %20)
br i1 %10, label %22, label %53
22: ; preds = %15
switch i32 %20, label %51 [
i32 0, label %23
i32 1, label %26
i32 2, label %30
i32 3, label %34
i32 4, label %37
i32 5, label %40
i32 6, label %44
i32 7, label %47
]
23: ; preds = %22
%24 = and i32 %17, 65280
%25 = or i32 %24, %21
br label %66
26: ; preds = %22
%27 = shl i32 %21, 4
%28 = and i32 %17, 255
%29 = or i32 %28, %27
br label %66
30: ; preds = %22
%31 = shl i32 %21, 4
%32 = and i32 %18, 255
%33 = or i32 %32, %31
br label %66
34: ; preds = %22
%35 = and i32 %18, 65280
%36 = or i32 %35, %21
br label %66
37: ; preds = %22
%38 = and i32 %17, 65280
%39 = or i32 %38, %21
br label %66
40: ; preds = %22
%41 = shl i32 %21, 4
%42 = and i32 %16, 255
%43 = or i32 %42, %41
br label %66
44: ; preds = %22
%45 = and i32 %19, 65280
%46 = or i32 %45, %21
br label %66
47: ; preds = %22
%48 = shl i32 %21, 4
%49 = and i32 %19, 255
%50 = or i32 %49, %48
br label %66
51: ; preds = %22
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 418)
br label %66
53: ; preds = %15
switch i32 %20, label %64 [
i32 0, label %54
i32 1, label %56
i32 2, label %59
i32 3, label %61
]
54: ; preds = %53
%55 = or i32 %17, %21
br label %66
56: ; preds = %53
%57 = shl i32 %21, 4
%58 = or i32 %17, %57
br label %66
59: ; preds = %53
%60 = or i32 %18, %21
br label %66
61: ; preds = %53
%62 = shl i32 %21, 4
%63 = or i32 %19, %62
br label %66
64: ; preds = %53
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 439)
br label %66
66: ; preds = %51, %47, %44, %40, %37, %34, %30, %26, %23, %64, %61, %59, %56, %54
%67 = phi i32 [ %16, %51 ], [ %16, %47 ], [ %16, %44 ], [ %43, %40 ], [ %39, %37 ], [ %16, %34 ], [ %16, %30 ], [ %16, %26 ], [ %16, %23 ], [ %16, %64 ], [ %16, %61 ], [ %16, %59 ], [ %16, %56 ], [ %16, %54 ]
%68 = phi i32 [ %17, %51 ], [ %17, %47 ], [ %17, %44 ], [ %17, %40 ], [ %17, %37 ], [ %17, %34 ], [ %17, %30 ], [ %29, %26 ], [ %25, %23 ], [ %17, %64 ], [ %17, %61 ], [ %17, %59 ], [ %58, %56 ], [ %55, %54 ]
%69 = phi i32 [ %18, %51 ], [ %18, %47 ], [ %18, %44 ], [ %18, %40 ], [ %18, %37 ], [ %36, %34 ], [ %33, %30 ], [ %18, %26 ], [ %18, %23 ], [ %18, %64 ], [ %18, %61 ], [ %60, %59 ], [ %18, %56 ], [ %18, %54 ]
%70 = phi i32 [ %19, %51 ], [ %50, %47 ], [ %46, %44 ], [ %19, %40 ], [ %19, %37 ], [ %19, %34 ], [ %19, %30 ], [ %19, %26 ], [ %19, %23 ], [ %19, %64 ], [ %63, %61 ], [ %19, %59 ], [ %19, %56 ], [ %19, %54 ]
%71 = add nuw nsw i32 %20, 1
%72 = icmp eq i32 %71, %1
br i1 %72, label %73, label %15
73: ; preds = %66
store i32 %70, i32* %11
store i32 %69, i32* %12
store i32 %68, i32* %13
store i32 %67, i32* %14
br label %74
74: ; preds = %73, %2
%75 = call i32 @strcpy(i8* %6, i8* %0)
%76 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%77 = load i32, i32* @O_RDWR
%78 = call i32 @open(i8* %6, i32 %77)
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %74
%81 = load i32, i32* @errno
%82 = call i8* @strerror(i32 %81)
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %82)
br label %102
84: ; preds = %74
%85 = load i32, i32* @SEEK_SET
%86 = call i32 @lseek(i32 %78, i32 180, i32 %85)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %92
88: ; preds = %84
%89 = load i32, i32* @errno
%90 = call i8* @strerror(i32 %89)
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %90)
br label %102
92: ; preds = %84
%93 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%94 = call i32 @write(i32 %78, i32* %93, i32 16)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %100
96: ; preds = %92
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %98)
br label %102
100: ; preds = %92
%101 = call i32 @close(i32 %78)
br label %102
102: ; preds = %100, %96, %88, %80
ret void
}