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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strstr(char *, char *);
char *strtok(char *, char *);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
void map_pci_mmconfig_addr() {
  char *mybuf, *mystr;
  int i = 0;
  FILE *mystream;
  uint64_t myval = 0;
  if (mystream = fopen("/sys/devices/pci0000:3a/0000:3a:0a.6/resource", "r")) {
    mybuf = malloc(65536);
    if (fread(mybuf, 1, 65536, mystream) > 0) {
      mystr = strtok(mybuf, "\n");
      myval = strtol(mystr, NULL, 16);
      printf("%s %lf\n", mystr, myval);
      while (mystr) {
        if (strstr(mystr, "PCI MMCONFIG 0000")) {
          myval = strtol(mystr, NULL, 16);
          break;
        }
        mystr = strtok(NULL, "\n");
      }
    }
    free(mybuf);
    fclose(mystream);
  } else
    printf("ERror");
  return;
}


x86 assembly (clang, -O0):
<map_pci_mmconfig_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe53(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12a8 <map_pci_mmconfig_addr+0x118>
mov    $0x10000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
jle    1291 <map_pci_mmconfig_addr+0x101>
mov    -0x8(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     128c <map_pci_mmconfig_addr+0xfc>
mov    -0x10(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     1273 <map_pci_mmconfig_addr+0xe3>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %eax,-0x24(%rbp)
jmp    128c <map_pci_mmconfig_addr+0xfc>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb6(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x10(%rbp)
jmp    1234 <map_pci_mmconfig_addr+0xa4>
jmp    1291 <map_pci_mmconfig_addr+0x101>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
jmp    12b6 <map_pci_mmconfig_addr+0x126>
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<map_pci_mmconfig_addr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xe60(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1254 <map_pci_mmconfig_addr+0xc4>
mov    %rax,%r15
mov    $0x10000,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jle    127a <map_pci_mmconfig_addr+0xea>
lea    0xe4a(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strtok@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
lea    0xe23(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     127a <map_pci_mmconfig_addr+0xea>
lea    0xe13(%rip),%r12
lea    0xe0a(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
jne    126b <map_pci_mmconfig_addr+0xdb>
xor    %edi,%edi
mov    %r13,%rsi
call   10a0 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1230 <map_pci_mmconfig_addr+0xa0>
jmp    127a <map_pci_mmconfig_addr+0xea>
lea    0xded(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"/sys/devices/pci0000:3a/0000:3a:0a.6/resource\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [8 x i8] c"%s %lf\0A\00"
@.str.4 = [18 x i8] c"PCI MMCONFIG 0000\00"
@.str.5 = [6 x i8] c"ERror\00"
define void @map_pci_mmconfig_addr() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %40
8: ; preds = %0
%9 = call i8* @malloc(i32 65536)
store i8* %9, i8** %1
%10 = load i8*, i8** %1
%11 = load i32*, i32** %4
%12 = call i64 @fread(i8* %10, i32 1, i32 65536, i32* %11)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %8
%15 = load i8*, i8** %1
%16 = call i8* @strtok(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %16, i8** %2
%17 = load i8*, i8** %2
%18 = call i32 @strtol(i8* %17, i32* null, i32 16)
store i32 %18, i32* %5
%19 = load i8*, i8** %2
%20 = load i32, i32* %5
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %19, i32 %20)
br label %22
22: ; preds = %32, %14
%23 = load i8*, i8** %2
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i8*, i8** %2
%27 = call i64 @strstr(i8* %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i8*, i8** %2
%31 = call i32 @strtol(i8* %30, i32* null, i32 16)
store i32 %31, i32* %5
br label %34
32: ; preds = %25
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %33, i8** %2
br label %22
34: ; preds = %29, %22
br label %35
35: ; preds = %34, %8
%36 = load i8*, i8** %1
%37 = call i32 @free(i8* %36)
%38 = load i32*, i32** %4
%39 = call i32 @fclose(i32* %38)
br label %42
40: ; preds = %0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
ret void
}

LLVM IR (-O2):
@.str = [46 x i8] c"/sys/devices/pci0000:3a/0000:3a:0a.6/resource\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [8 x i8] c"%s %lf\0A\00"
@.str.4 = [18 x i8] c"PCI MMCONFIG 0000\00"
@.str.5 = [6 x i8] c"ERror\00"
define void @map_pci_mmconfig_addr() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %24, label %3
3: ; preds = %0
%4 = tail call dereferenceable_or_null(65536) i8* @malloc(i32 65536)
%5 = tail call i64 @fread(i8* %4, i32 1, i32 65536, i32* %1)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %3
%8 = tail call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @strtol(i8* nocapture %8, i32* null, i32 16)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %8, i32 %9)
%11 = icmp eq i8* %8, null
br i1 %11, label %21, label %12
12: ; preds = %7, %18
%13 = phi i8* [ %19, %18 ], [ %8, %7 ]
%14 = tail call i64 @strstr(i8* %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @strtol(i8* nocapture %13, i32* null, i32 16)
br label %21
18: ; preds = %12
%19 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %12
21: ; preds = %18, %7, %16, %3
%22 = tail call i32 @free(i8* %4)
%23 = tail call i32 @fclose(i32* %1)
br label %26
24: ; preds = %0
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
ret void
}