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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
FILE *open_pci_ids(void) {
  int i;
  char *pci_ids_path;
  FILE *fp;
  const char *pci_ids[] = {"/usr/share/hwdata/pci.ids", "/usr/share/pci.ids",
                           "/usr/share/misc/pci.ids", NULL};
  if ((pci_ids_path = getenv("PCI_IDS_PATH")) != NULL) {
    if ((fp = fopen(pci_ids_path, "r")) != NULL) {
      return fp;
    } else {
      perror(pci_ids_path);
      return NULL;
    }
  }
  for (i = 0; pci_ids[i] != NULL; i++) {
    if ((fp = fopen(pci_ids[i], "r")) != NULL)
      return fp;
  }
  fprintf(stderr, "Could not find pci.ids file\n");
  return NULL;
}


x86 assembly (clang, -O0):
<open_pci_ids>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2ca1(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c9e(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c9b(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c98(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11cf <open_pci_ids+0x8f>
mov    -0x18(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11b9 <open_pci_ids+0x79>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <open_pci_ids+0x106>
mov    -0x18(%rbp),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1246 <open_pci_ids+0x106>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmpq   $0x0,-0x40(%rbp,%rax,8)
je     1229 <open_pci_ids+0xe9>
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
lea    0xe5c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1216 <open_pci_ids+0xd6>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <open_pci_ids+0x106>
jmp    121b <open_pci_ids+0xdb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d6 <open_pci_ids+0x96>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_pci_ids>:
push   %rbx
lea    0xefd(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116b <open_pci_ids+0x2b>
mov    %rax,%rbx
lea    0xef6(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ca <open_pci_ids+0x8a>
pop    %rbx
ret
lea    0xe8e(%rip),%rdi
lea    0xed9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    1169 <open_pci_ids+0x29>
lea    0xe90(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    1169 <open_pci_ids+0x29>
lea    0xe8b(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    1169 <open_pci_ids+0x29>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11d2 <open_pci_ids+0x92>
mov    %rbx,%rdi
call   1060 <perror@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"/usr/share/hwdata/pci.ids\00"
@.str.1 = [19 x i8] c"/usr/share/pci.ids\00"
@.str.2 = [24 x i8] c"/usr/share/misc/pci.ids\00"
@__const.open_pci_ids.pci_ids = [4 x i8*] [i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [13 x i8] c"PCI_IDS_PATH\00"
@.str.4 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.5 = [29 x i8] c"Could not find pci.ids file\0A\00"
define i32* @open_pci_ids() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [4 x i8*]
%6 = bitcast [4 x i8*]* %5 to i8*
%7 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i8* %7, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %18
9: ; preds = %0
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %11, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i32*, i32** %4
store i32* %14, i32** %1
br label %41
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i32 @perror(i8* %16)
store i32* null, i32** %1
br label %41
18: ; preds = %0
store i32 0, i32* %2
br label %19
19: ; preds = %35, %18
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %38
25: ; preds = %19
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %30, i32** %4
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = load i32*, i32** %4
store i32* %33, i32** %1
br label %41
34: ; preds = %25
br label %35
35: ; preds = %34
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
store i32 %37, i32* %2
br label %19
38: ; preds = %19
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
store i32* null, i32** %1
br label %41
41: ; preds = %38, %32, %15, %13
%42 = load i32*, i32** %1
ret i32* %42
}

LLVM IR (-O2):
@.str = [26 x i8] c"/usr/share/hwdata/pci.ids\00"
@.str.1 = [19 x i8] c"/usr/share/pci.ids\00"
@.str.2 = [24 x i8] c"/usr/share/misc/pci.ids\00"
@.str.3 = [13 x i8] c"PCI_IDS_PATH\00"
@.str.4 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.5 = [29 x i8] c"Could not find pci.ids file\0A\00"
define noalias i32* @open_pci_ids() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %11, label %20
6: ; preds = %0
%7 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = tail call i32 @perror(i8* %1)
br label %20
11: ; preds = %3
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %20
20: ; preds = %3, %11, %14, %6, %17, %9
%21 = phi i32* [ null, %9 ], [ null, %17 ], [ %7, %6 ], [ %4, %3 ], [ %12, %11 ], [ %15, %14 ]
ret i32* %21
}