#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int read(int, int *, int);
int main(int argc, char *argv[]) {
  int fd, j;
  char *nodename = "/dev/mycdrv";
  int *interrupts = malloc((256 * sizeof(int)));
  if (argc > 1)
    nodename = argv[1];
  if ((fd = open(nodename, O_RDONLY)) < 0) {
    perror("opening device node");
    exit(errno);
  };
  ;
  if (read(fd, interrupts, (256 * sizeof(int))) != (256 * sizeof(int))) {
    perror("reading interrupts");
    exit(errno);
  };
  ;
  for (j = 0; j < 256; j++)
    if (interrupts[j] > 0)
      printf(" %4d %10d\n", j, interrupts[j]);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11a5 <main+0x45>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11dd <main+0x7d>
lea    0xe42(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cltq
cmp    $0x400,%rax
je     1216 <main+0xb6>
lea    0xe1d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    1269 <main+0x109>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    1256 <main+0xf6>
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xde2(%rip),%rdi
call   1030 <printf@plt>
jmp    125b <main+0xfb>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    121d <main+0xbd>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
cmp    $0x2,%ebp
jl     1184 <main+0x24>
mov    0x8(%rbx),%rdi
jmp    118b <main+0x2b>
lea    0xe75(%rip),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
jns    11a6 <main+0x46>
lea    0xe68(%rip),%rdi
jmp    11f8 <main+0x98>
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cmp    $0x400,%eax
jne    11f1 <main+0x91>
xor    %ebx,%ebx
lea    0xe6e(%rip),%r15
jmp    11dd <main+0x7d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x100,%rbx
je     120b <main+0xab>
mov    (%r14,%rbx,4),%edx
test   %edx,%edx
jle    11d0 <main+0x70>
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
jmp    11d0 <main+0x70>
lea    0xe28(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/mycdrv\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"opening device node\00"
@errno = global i32 0
@.str.2 = [19 x i8] c"reading interrupts\00"
@.str.3 = [11 x i8] c" %4d %10d\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 i8*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %8
%10 = call i32* @malloc(i32 1024)
store i32* %10, i32** %9
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %8
br label %17
17: ; preds = %13, %2
%18 = load i8*, i8** %8
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @errno
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %17
%27 = load i32, i32* %6
%28 = load i32*, i32** %9
%29 = call i32 @read(i32 %27, i32* %28, i32 1024)
%30 = sext i32 %29 to i64
%31 = icmp ne i64 %30, 1024
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* @errno
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %26
store i32 0, i32* %7
br label %37
37: ; preds = %56, %36
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 256
br i1 %39, label %40, label %59
40: ; preds = %37
%41 = load i32*, i32** %9
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %40
%48 = load i32, i32* %7
%49 = load i32*, i32** %9
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
%54 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %48, i32 %53)
br label %55
55: ; preds = %47, %40
br label %56
56: ; preds = %55
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %37
59: ; preds = %37
%60 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/mycdrv\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"opening device node\00"
@errno = global i32 0
@.str.2 = [19 x i8] c"reading interrupts\00"
@.str.3 = [11 x i8] c" %4d %10d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32* @malloc(i32 1024)
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
br label %8
8: ; preds = %5, %2
%9 = phi i8* [ %7, %5 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @errno
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %8
%18 = tail call i32 @read(i32 %11, i32* %3, i32 1024)
%19 = icmp eq i32 %18, 1024
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @errno
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %17, %32
%25 = phi i64 [ %33, %32 ], [ 0, %17 ]
%26 = getelementptr inbounds i32, i32* %3, i64 %25
%27 = load i32, i32* %26
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = trunc i64 %25 to i32
%31 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %27)
br label %32
32: ; preds = %24, %29
%33 = add nuw nsw i64 %25, 1
%34 = icmp eq i64 %33, 256
br i1 %34, label %35, label %24
35: ; preds = %32
%36 = tail call i32 @exit(i32 0)
unreachable
}