#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*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ log_msg(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int check_pci_id(char *path, char *pci_id) {
  FILE *f;
  char *pci_id_rc, pci_id_buf[7];
  f = fopen(path, "r");
  if (!f) {
    log_msg("Unable to open file '%s'", path);
    return -1;
  }
  pci_id_rc = fgets(pci_id_buf, 7, f);
  if (!pci_id_rc) {
    log_msg("Unable to read file '%s'", path);
    fclose(f);
    return -1;
  }
  fclose(f);
  return !!strncmp(pci_id, pci_id_buf, 7);
}


x86 assembly (clang, -O0):
<check_pci_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119b <check_pci_id+0x4b>
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1060 <log_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120e <check_pci_id+0xbe>
lea    -0x2f(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x7,%esi
call   1050 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e1 <check_pci_id+0x91>
mov    -0x10(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1060 <log_msg@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120e <check_pci_id+0xbe>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    -0x2f(%rbp),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_pci_id>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11af <check_pci_id+0x5f>
mov    %rax,%rbx
lea    0x9(%rsp),%rdi
mov    $0x7,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <check_pci_id+0x70>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0x9(%rsp),%rsi
mov    %r14,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
jmp    11dc <check_pci_id+0x8c>
lea    0xe4c(%rip),%rdi
mov    %r15,%rsi
call   1060 <log_msg@plt>
jmp    11d7 <check_pci_id+0x87>
lea    0xe54(%rip),%rdi
mov    %r15,%rsi
call   1060 <log_msg@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Unable to open file '%s'\00"
@.str.2 = [25 x i8] c"Unable to read file '%s'\00"
define i32 @check_pci_id(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [7 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @log_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %37
16: ; preds = %2
%17 = getelementptr inbounds [7 x i8], [7 x i8]* %8, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i8* @fgets(i8* %17, i32 7, i32* %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = call i32 @log_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
store i32 -1, i32* %3
br label %37
27: ; preds = %16
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %5
%31 = getelementptr inbounds [7 x i8], [7 x i8]* %8, i64 0, i64 0
%32 = call i32 @strncmp(i8* %30, i8* %31, i32 7)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
%35 = xor i1 %34, true
%36 = zext i1 %35 to i32
store i32 %36, i32* %3
br label %37
37: ; preds = %27, %22, %13
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Unable to open file '%s'\00"
@.str.2 = [25 x i8] c"Unable to read file '%s'\00"
define i32 @check_pci_id(i8* %0, i8* %1) {
%3 = alloca [7 x i8]
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @log_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
9: ; preds = %2
%10 = call i8* @fgets(i8* %4, i32 7, i32* %5)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 @log_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%14 = call i32 @fclose(i32* %5)
br label %20
15: ; preds = %9
%16 = call i32 @fclose(i32* %5)
%17 = call i32 @strncmp(i8* %1, i8* %4, i32 7)
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %15, %12, %7
%21 = phi i32 [ %19, %15 ], [ -1, %12 ], [ -1, %7 ]
ret i32 %21
}