#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 off_t;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int O_RDWR;
int O_SYNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGE_SIZE;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, int,
                           char *);
void *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
int /*<<< orphan*/ sysconf(int /*<<< orphan*/);
int main() {
  int fd;
  off_t target = 10;
  if ((fd = open("/sys/devices/pci0000:3a/0000:3a:0a.6/config",
                 O_RDWR | O_SYNC)) == -1)
    do {
      fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 68,
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/PourroyJean/performance_modelisation/"
              "refs/heads/master/src/tool_PMU/uncore_pci/pci_linux_driver.c",
              errno, strerror(errno));
      exit(1);
    } while (0);
  printf("Target offset is 0x%x, page size is %ld\n", (int)target,
         sysconf(_SC_PAGE_SIZE));
  fflush(stdout);
  void *ptr = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  printf("PCI BAR0 0x0000 = 0x%4x\n", *((unsigned short *)ptr));
  printf("ok");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0xc(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    0x2e2a(%rip),%rax
or     (%rax),%esi
lea    0xe51(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1217 <main+0x97>
jmp    11c5 <main+0x45>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%r8d
mov    %rax,%r9
lea    0xe30(%rip),%rsi
mov    $0x44,%edx
lea    0xe49(%rip),%rcx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
mov    0x2d54(%rip),%rax
or     (%rax),%edx
mov    0x2d83(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x1000,%esi
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzwl (%rax),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e4e(%rip),%rax
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe64(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1232 <main+0xb2>
mov    %eax,%ebx
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
lea    0xf4c(%rip),%rdi
mov    $0xa,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2e14(%rip),%rax
mov    0x2dc5(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2df2(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
movzwl (%rax),%esi
lea    0xf22(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf2d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d87(%rip),%rax
mov    (%rax),%ebx
mov    0x2d76(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10a0 <strerror@plt>
lea    0xdda(%rip),%rsi
lea    0xdf8(%rip),%rcx
mov    %ebx,%edi
mov    $0x44,%edx
mov    %ebp,%r8d
mov    %rax,%r9
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"/sys/devices/pci0000:3a/0000:3a:0a.6/config\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"Error at line %d, file %s (%d) [%s]\0A\00"
@.str.2 = [188 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/PourroyJean/performance_modelisation/refs/heads/master/src/tool_PMU/uncore_pci/pci_linux_driver.c\00"
@errno = global i32 0
@.str.3 = [41 x i8] c"Target offset is 0x%x, page size is %ld\0A\00"
@_SC_PAGE_SIZE = global i32 0
@stdout = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [25 x i8] c"PCI BAR0 0x0000 = 0x%4x\0A\00"
@.str.5 = [3 x i8] c"ok\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
store i32 10, i32* %3
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_SYNC
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %0
br label %11
11: ; preds = %10
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 68, i8* getelementptr inbounds ([188 x i8], [188 x i8]* @.str.2, i64 0, i64 0), i32 %13, i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; No predecessors!
br label %19
19: ; preds = %18, %0
%20 = load i32, i32* %3
%21 = load i32, i32* @_SC_PAGE_SIZE
%22 = call i32 @sysconf(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %22)
%24 = load i32, i32* @stdout
%25 = call i32 @fflush(i32 %24)
%26 = load i32, i32* @PROT_READ
%27 = load i32, i32* @PROT_WRITE
%28 = or i32 %26, %27
%29 = load i32, i32* @MAP_SHARED
%30 = load i32, i32* %2
%31 = call i8* @mmap(i32 0, i32 4096, i32 %28, i32 %29, i32 %30, i32 0)
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = bitcast i8* %32 to i16*
%34 = load i16, i16* %33
%35 = zext i16 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [44 x i8] c"/sys/devices/pci0000:3a/0000:3a:0a.6/config\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"Error at line %d, file %s (%d) [%s]\0A\00"
@.str.2 = [188 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/PourroyJean/performance_modelisation/refs/heads/master/src/tool_PMU/uncore_pci/pci_linux_driver.c\00"
@errno = global i32 0
@.str.3 = [41 x i8] c"Target offset is 0x%x, page size is %ld\0A\00"
@_SC_PAGE_SIZE = global i32 0
@stdout = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [25 x i8] c"PCI BAR0 0x0000 = 0x%4x\0A\00"
@.str.5 = [3 x i8] c"ok\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_SYNC
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 68, i8* getelementptr inbounds ([188 x i8], [188 x i8]* @.str.2, i64 0, i64 0), i32 %8, i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* @_SC_PAGE_SIZE
%14 = tail call i32 @sysconf(i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 10, i32 %14)
%16 = load i32, i32* @stdout
%17 = tail call i32 @fflush(i32 %16)
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* @PROT_WRITE
%20 = or i32 %19, %18
%21 = load i32, i32* @MAP_SHARED
%22 = tail call i8* @mmap(i32 0, i32 4096, i32 %20, i32 %21, i32 %4, i32 0)
%23 = bitcast i8* %22 to i16*
%24 = load i16, i16* %23
%25 = zext i16 %24 to i32
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}