#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 uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int detect_arch();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ stderr;
FILE *open_header(char *a) {
  FILE *header = NULL;
  char fname[128];
  uint64_t arch = detect_arch();
  switch (arch) {
  case 0x3C:
  case 0x45:
  case 0x46:
  case 0x3D:
  case 0x47:
  case 0x4F:
  case 0x56:
    arch = 0x3F;
    break;
  case 0x3A:
    arch = 0x3E;
    break;
  case 0x2F:
  case 0x2A:
    arch = 0x2D;
    break;
  }
  if (a) {
    snprintf(fname, 128, "headers/intel%s.h", a);
  } else {
    snprintf(fname, 128, "headers/intel%lX.h", arch);
  }
  header = fopen(fname, "r");
  if (header == NULL) {
    fprintf(stderr, "ERROR: unable to open file %s\n", fname);
    if (a) {
      fprintf(stderr,
              "architecture %s may not be supported. No header files found.\n",
              a);
    } else {
      fprintf(stderr,
              "architecture %lx may not be supported. Use -f[arch number] to "
              "force.\n",
              arch);
    }
    exit(-1);
  }
  return header;
}


x86 assembly (clang, -O0):
<open_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
xor    %eax,%eax
call   1040 <detect_arch@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%eax
mov    %eax,-0x98(%rbp)
sub    $0x2a,%eax
je     122a <open_header+0xda>
jmp    118e <open_header+0x3e>
mov    -0x98(%rbp),%eax
sub    $0x2f,%eax
je     122a <open_header+0xda>
jmp    11a2 <open_header+0x52>
mov    -0x98(%rbp),%eax
sub    $0x3a,%eax
je     121b <open_header+0xcb>
jmp    11b6 <open_header+0x66>
mov    -0x98(%rbp),%eax
add    $0xffffffc4,%eax
sub    $0x2,%eax
jb     120c <open_header+0xbc>
jmp    11cd <open_header+0x7d>
mov    -0x98(%rbp),%eax
add    $0xffffffbb,%eax
sub    $0x3,%eax
jb     120c <open_header+0xbc>
jmp    11e4 <open_header+0x94>
mov    -0x98(%rbp),%eax
sub    $0x4f,%eax
je     120c <open_header+0xbc>
jmp    11f8 <open_header+0xa8>
mov    -0x98(%rbp),%eax
sub    $0x56,%eax
jne    1234 <open_header+0xe4>
jmp    120c <open_header+0xbc>
movl   $0x3f,-0x94(%rbp)
jmp    1234 <open_header+0xe4>
movl   $0x3e,-0x94(%rbp)
jmp    1234 <open_header+0xe4>
movl   $0x2d,-0x94(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1262 <open_header+0x112>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x80,%esi
lea    0xdaa(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1282 <open_header+0x132>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%ecx
mov    $0x80,%esi
lea    0xd97(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xd95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1314 <open_header+0x1c4>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
lea    0xd6c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpq   $0x0,-0x8(%rbp)
je     12ed <open_header+0x19d>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    130a <open_header+0x1ba>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    -0x94(%rbp),%edx
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_header>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <detect_arch@plt>
mov    %eax,%ebp
add    $0xffffffd6,%eax
cmp    $0x2c,%eax
ja     11a3 <open_header+0x53>
movabs $0x1020380c0000,%rcx
bt     %rax,%rcx
jae    1186 <open_header+0x36>
mov    $0x3f,%ebp
jmp    11a3 <open_header+0x53>
mov    $0x21,%ecx
bt     %rax,%rcx
jae    1198 <open_header+0x48>
mov    $0x2d,%ebp
jmp    11a3 <open_header+0x53>
cmp    $0x10,%rax
jne    11a3 <open_header+0x53>
mov    $0x3e,%ebp
test   %rbx,%rbx
je     11c3 <open_header+0x73>
lea    0xe51(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11db <open_header+0x8b>
lea    0xe48(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0xe43(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fb <open_header+0xab>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dde(%rip),%r14
mov    (%r14),%edi
lea    0xe1b(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edi
test   %rbx,%rbx
jne    1238 <open_header+0xe8>
lea    0xe5f(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe07(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"headers/intel%s.h\00"
@.str.1 = [19 x i8] c"headers/intel%lX.h\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"ERROR: unable to open file %s\0A\00"
@.str.4 = [62 x i8] c"architecture %s may not be supported. No header files found.\0A\00"
@.str.5 = [70 x i8] c"architecture %lx may not be supported. Use -f[arch number] to force.\0A\00"
define i32* @open_header(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [128 x i8]
%5 = alloca i32
store i8* %0, i8** %2
store i32* null, i32** %3
%6 = call i32 (...) @detect_arch()
store i32 %6, i32* %5
%7 = load i32, i32* %5
switch i32 %7, label %11 [
i32 60, label %8
i32 69, label %8
i32 70, label %8
i32 61, label %8
i32 71, label %8
i32 79, label %8
i32 86, label %8
i32 58, label %9
i32 47, label %10
i32 42, label %10
]
8: ; preds = %1, %1, %1, %1, %1, %1, %1
store i32 63, i32* %5
br label %11
9: ; preds = %1
store i32 62, i32* %5
br label %11
10: ; preds = %1, %1
store i32 45, i32* %5
br label %11
11: ; preds = %1, %10, %9, %8
%12 = load i8*, i8** %2
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%16 = load i8*, i8** %2
%17 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %15, i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %22
18: ; preds = %11
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%20 = load i32, i32* %5
%21 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %19, i32 128, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %14
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %3
%25 = load i32*, i32** %3
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %43
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %2
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %2
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0), i8* %35)
br label %41
37: ; preds = %27
%38 = load i32, i32* @stderr
%39 = load i32, i32* %5
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %37, %33
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %22
%44 = load i32*, i32** %3
ret i32* %44
}

LLVM IR (-O2):
@.str = [18 x i8] c"headers/intel%s.h\00"
@.str.1 = [19 x i8] c"headers/intel%lX.h\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"ERROR: unable to open file %s\0A\00"
@.str.4 = [62 x i8] c"architecture %s may not be supported. No header files found.\0A\00"
@.str.5 = [70 x i8] c"architecture %lx may not be supported. Use -f[arch number] to force.\0A\00"
define noalias i32* @open_header(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @detect_arch()
switch i32 %4, label %8 [
i32 60, label %5
i32 69, label %5
i32 70, label %5
i32 61, label %5
i32 71, label %5
i32 79, label %5
i32 86, label %5
i32 58, label %6
i32 47, label %7
i32 42, label %7
]
5: ; preds = %1, %1, %1, %1, %1, %1, %1
br label %8
6: ; preds = %1
br label %8
7: ; preds = %1, %1
br label %8
8: ; preds = %1, %7, %6, %5
%9 = phi i32 [ %4, %1 ], [ 45, %7 ], [ 62, %6 ], [ 63, %5 ]
%10 = icmp eq i8* %0, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %15
13: ; preds = %8
%14 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 128, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %15
15: ; preds = %13, %11
%16 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%21 = load i32, i32* @stderr
br i1 %10, label %24, label %22
22: ; preds = %18
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %26
24: ; preds = %18
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0), i32 %9)
br label %26
26: ; preds = %24, %22
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %15
ret i32* %16
}