#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *my_file;
  int result;
  if (argc < 3) {
    fprintf(stderr, "Usage: process id, ppout specific\n");
    return 0;
  }
  char addr_specs_a[256];
  sprintf(addr_specs_a, "/proc/%s/hw/ioreg/%s_a", argv[1], argv[2]);
  char my_buffer[1024];
  int ii;
  printf("This program does a file open of addr_specs_a 100,000 times.\n");
  for (ii = 0; ii < 100000; ii++) {
    my_file = fopen(addr_specs_a, "r");
    result = fread(my_buffer, 1, 1024, my_file);
    fclose(my_file);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a4 <main+0x44>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1245 <main+0xe5>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe61(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xe6c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x524(%rbp)
cmpl   $0x186a0,-0x524(%rbp)
jge    123e <main+0xde>
lea    -0x120(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x520(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x524(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x524(%rbp)
jmp    11dd <main+0x7d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x530,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x500,%rsp
cmp    $0x2,%edi
jg     118b <main+0x2b>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1200 <main+0xa0>
mov    0x8(%rsi),%rdx
mov    0x10(%rsi),%rcx
lea    0xe89(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1080 <sprintf@plt>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
mov    $0x186a0,%ebp
lea    0xe7d(%rip),%r15
lea    0x100(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0x70>
xor    %eax,%eax
add    $0x500,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Usage: process id, ppout specific\0A\00"
@.str.1 = [23 x i8] c"/proc/%s/hw/ioreg/%s_a\00"
@.str.2 = [62 x i8] c"This program does a file open of addr_specs_a 100,000 times.\0A\00"
@.str.3 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %41
16: ; preds = %2
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %10
br label %26
26: ; preds = %37, %16
%27 = load i32, i32* %10
%28 = icmp slt i32 %27, 100000
br i1 %28, label %29, label %40
29: ; preds = %26
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %6
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%33 = load i32*, i32** %6
%34 = call i32 @fread(i8* %32, i32 1, i32 1024, i32* %33)
store i32 %34, i32* %7
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %29
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %26
40: ; preds = %26
store i32 0, i32* %3
br label %41
41: ; preds = %40, %13
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Usage: process id, ppout specific\0A\00"
@.str.1 = [23 x i8] c"/proc/%s/hw/ioreg/%s_a\00"
@.str.3 = [2 x i8] c"r\00"
@str = [61 x i8] c"This program does a file open of addr_specs_a 100,000 times.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [1024 x i8]
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %26
9: ; preds = %2
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %14)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %9, %18
%19 = phi i32 [ 0, %9 ], [ %23, %18 ]
%20 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @fread(i8* %16, i32 1, i32 1024, i32* %20)
%22 = tail call i32 @fclose(i32* %20)
%23 = add nuw nsw i32 %19, 1
%24 = icmp eq i32 %23, 100000
br i1 %24, label %25, label %18
25: ; preds = %18
br label %26
26: ; preds = %25, %6
ret i32 0
}