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

/* Variables and functions */
char *detect_arch();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
FILE *open_header(char *a) {
  FILE *header = NULL;
  char fname[128];
  uint64_t arch = detect_arch();
  if (a != NULL) {
    snprintf(fname, 128, "platform_headers/Intel%s.h", a);
  } else {
    snprintf(fname, 128, "platform_headers/Intel%lX.h", arch);
  }
  header = fopen(fname, "r");
  if (header == NULL) {
    fprintf(stderr, "ERROR: unable to open file %s\n", fname);
    if (a != NULL) {
      fprintf(stderr,
              "Model %s may not be supported. No matching header files found "
              "in platform_headers/.\n",
              a);
    } else {
      fprintf(stderr, "Model %lx may not be supported. Use -f 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)
mov    $0x0,%al
call   1040 <detect_arch@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a1 <open_header+0x51>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x80,%esi
lea    0xe69(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11c0 <open_header+0x70>
lea    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rcx
mov    $0x80,%esi
lea    0xe60(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    124d <open_header+0xfd>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
lea    0xe40(%rip),%rsi
call   1050 <fprintf@plt>
cmpq   $0x0,-0x8(%rbp)
je     1227 <open_header+0xd7>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1243 <open_header+0xf3>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    -0x98(%rbp),%rdx
lea    0xe6f(%rip),%rsi
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   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <detect_arch@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1182 <open_header+0x32>
lea    0xe8b(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
jmp    1194 <open_header+0x44>
lea    0xe92(%rip),%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
call   1030 <snprintf@plt>
lea    0xe97(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ba <open_header+0x6a>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e1f(%rip),%r15
mov    (%r15),%edi
lea    0xe6e(%rip),%rsi
mov    %rsp,%rdx
call   1050 <fprintf@plt>
mov    (%r15),%edi
test   %rbx,%rbx
jne    11e7 <open_header+0x97>
lea    0xecb(%rip),%rsi
mov    %r14,%rdx
jmp    11f1 <open_header+0xa1>
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"platform_headers/Intel%s.h\00"
@.str.1 = [28 x i8] c"platform_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 = [85 x i8] c"Model %s may not be supported. No matching header files found in platform_headers/.\0A\00"
@.str.5 = [50 x i8] c"Model %lx may not be supported. Use -f to force.\0A\00"
define i32* @open_header(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [128 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
store i32* null, i32** %3
%6 = call i8* (...) @detect_arch()
store i8* %6, i8** %5
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = call i32 @snprintf(i8* %10, i32 128, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %17
13: ; preds = %1
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i32 @snprintf(i8* %14, i32 128, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %13, %9
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %3
%20 = load i32*, i32** %3
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %38
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %2
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %2
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.4, i64 0, i64 0), i8* %30)
br label %36
32: ; preds = %22
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %5
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %32, %28
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %17
%39 = load i32*, i32** %3
ret i32* %39
}

LLVM IR (-O2):
@.str = [27 x i8] c"platform_headers/Intel%s.h\00"
@.str.1 = [28 x i8] c"platform_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 = [85 x i8] c"Model %s may not be supported. No matching header files found in platform_headers/.\0A\00"
@.str.5 = [50 x i8] c"Model %lx may not be supported. Use -f 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 i8* (...) @detect_arch()
%5 = icmp eq i8* %0, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = call i32 @snprintf(i8* %3, i32 128, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %10
8: ; preds = %1
%9 = call i32 @snprintf(i8* %3, i32 128, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %10
10: ; preds = %8, %6
%11 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%16 = load i32, i32* @stderr
br i1 %5, label %19, label %17
17: ; preds = %13
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %21
19: ; preds = %13
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %21
21: ; preds = %19, %17
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %10
ret i32* %11
}