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

/* Variables and functions */
int /*<<< orphan*/ dp_priority_locl_end();
int /*<<< orphan*/ dp_priority_locl_start();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Dette programet leser en fil\n\n\tBruk: ./dptest file\n");
    exit(0);
  }
  FILE *FH;
  int count = 0;
  char buf[1024];
  int n;
  dp_priority_locl_start();
  if ((FH = fopen(argv[1], "r")) == NULL) {
    perror(argv[1]);
    exit(1);
  }
  while ((n = fread(buf, sizeof(char), sizeof(buf), FH)) > 0) {
    count += n;
  }
  fclose(FH);
  dp_priority_locl_end();
  printf("did read %i bytes\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b8 <main+0x38>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1080 <dp_priority_locl_start@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ff <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1204 <main+0x84>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jle    123e <main+0xbe>
mov    -0x424(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1204 <main+0x84>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   1050 <dp_priority_locl_end@plt>
mov    -0x1c(%rbp),%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x1,%edi
jle    121d <main+0x8d>
mov    %rsi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1090 <dp_priority_locl_start@plt>
mov    0x8(%rbx),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1230 <main+0xa0>
mov    %rax,%r14
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %ebp,%ebx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
lea    (%rax,%rbx,1),%ebp
test   %eax,%eax
jg     11d0 <main+0x40>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   1060 <dp_priority_locl_end@plt>
lea    0xdfe(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x8(%rbx),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"Dette programet leser en fil\0A\0A\09Bruk: ./dptest file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"did read %i bytes\0A\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 [1024 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %2
store i32 0, i32* %7
%16 = call i32 (...) @dp_priority_locl_start()
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @perror(i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %15
br label %29
29: ; preds = %34, %28
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%31 = load i32*, i32** %6
%32 = call i32 @fread(i8* %30, i32 1, i32 1024, i32* %31)
store i32 %32, i32* %9
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* %9
%36 = load i32, i32* %7
%37 = add nsw i32 %36, %35
store i32 %37, i32* %7
br label %29
38: ; preds = %29
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
%41 = call i32 (...) @dp_priority_locl_end()
%42 = load i32, i32* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %42)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"did read %i bytes\0A\00"
@str = [51 x i8] c"Dette programet leser en fil\0A\0A\09Bruk: ./dptest file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = tail call i32 (...) @dp_priority_locl_start()
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i8*, i8** %11
%17 = tail call i32 @perror(i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %8, %19
%20 = phi i32 [ %23, %19 ], [ 0, %8 ]
%21 = call i32 @fread(i8* %9, i32 1, i32 1024, i32* %13)
%22 = icmp sgt i32 %21, 0
%23 = add nsw i32 %21, %20
br i1 %22, label %19, label %24
24: ; preds = %19
%25 = tail call i32 @fclose(i32* %13)
%26 = tail call i32 (...) @dp_priority_locl_end()
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %20)
ret i32 0
}