#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);
int read(int, int *, int);
int main(int argc, char *argv[]) {
  int fd, j;
  char *nodename = "/dev/mycdrv";
  int *interrupts = malloc((256 * sizeof(int)));
  int *bhs = 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);
  };
  ;
  if (read(fd, bhs, (256 * sizeof(int))) != (256 * sizeof(int))) {
    perror("reading bhs");
    exit(errno);
  };
  ;
  for (j = 0; j < 256; j++)
    if (interrupts[j] > 0)
      printf(" %4d %10d%10d\n", j, interrupts[j], bhs[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)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11eb <main+0x8b>
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df4(%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     1224 <main+0xc4>
lea    0xe0f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cltq
cmp    $0x400,%rax
je     125d <main+0xfd>
lea    0xde9(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    12bb <main+0x15b>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    12a8 <main+0x148>
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xd9c(%rip),%rdi
call   1030 <printf@plt>
jmp    12ad <main+0x14d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1264 <main+0x104>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
cmp    $0x2,%ebp
jl     1192 <main+0x32>
mov    0x8(%rbx),%rdi
jmp    1199 <main+0x39>
lea    0xe67(%rip),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
jns    11b4 <main+0x54>
lea    0xe5a(%rip),%rdi
jmp    1225 <main+0xc5>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cmp    $0x400,%eax
jne    1215 <main+0xb5>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cmp    $0x400,%eax
jne    121e <main+0xbe>
xor    %ebx,%ebx
lea    0xe54(%rip),%r12
jmp    11fd <main+0x9d>
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x100,%rbx
je     1238 <main+0xd8>
mov    (%r15,%rbx,4),%edx
test   %edx,%edx
jle    11f0 <main+0x90>
mov    (%r14,%rbx,4),%ecx
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
jmp    11f0 <main+0x90>
lea    0xe04(%rip),%rdi
jmp    1225 <main+0xc5>
lea    0xe0e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2da7(%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 = [12 x i8] c"reading bhs\00"
@.str.4 = [15 x i8] c" %4d %10d%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*
%10 = 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
%11 = call i32* @malloc(i32 1024)
store i32* %11, i32** %9
%12 = call i32* @malloc(i32 1024)
store i32* %12, i32** %10
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %8
br label %19
19: ; preds = %15, %2
%20 = load i8*, i8** %8
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @errno
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %19
%29 = load i32, i32* %6
%30 = load i32*, i32** %9
%31 = call i32 @read(i32 %29, i32* %30, i32 1024)
%32 = sext i32 %31 to i64
%33 = icmp ne i64 %32, 1024
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @errno
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %28
%39 = load i32, i32* %6
%40 = load i32*, i32** %10
%41 = call i32 @read(i32 %39, i32* %40, i32 1024)
%42 = sext i32 %41 to i64
%43 = icmp ne i64 %42, 1024
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @errno
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %38
store i32 0, i32* %7
br label %49
49: ; preds = %73, %48
%50 = load i32, i32* %7
%51 = icmp slt i32 %50, 256
br i1 %51, label %52, label %76
52: ; preds = %49
%53 = load i32*, i32** %9
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %72
59: ; preds = %52
%60 = load i32, i32* %7
%61 = load i32*, i32** %9
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = load i32*, i32** %10
%67 = load i32, i32* %7
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %66, i64 %68
%70 = load i32, i32* %69
%71 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %60, i32 %65, i32 %70)
br label %72
72: ; preds = %59, %52
br label %73
73: ; preds = %72
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %49
76: ; preds = %49
%77 = 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 = [12 x i8] c"reading bhs\00"
@.str.4 = [15 x i8] c" %4d %10d%10d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32* @malloc(i32 1024)
%4 = tail call i32* @malloc(i32 1024)
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
br label %9
9: ; preds = %6, %2
%10 = phi i8* [ %8, %6 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @errno
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %9
%19 = tail call i32 @read(i32 %12, i32* %3, i32 1024)
%20 = icmp eq i32 %19, 1024
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @errno
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %18
%26 = tail call i32 @read(i32 %12, i32* %4, i32 1024)
%27 = icmp eq i32 %26, 1024
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @errno
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %25, %42
%33 = phi i64 [ %43, %42 ], [ 0, %25 ]
%34 = getelementptr inbounds i32, i32* %3, i64 %33
%35 = load i32, i32* %34
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = getelementptr inbounds i32, i32* %4, i64 %33
%39 = load i32, i32* %38
%40 = trunc i64 %33 to i32
%41 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %40, i32 %35, i32 %39)
br label %42
42: ; preds = %32, %37
%43 = add nuw nsw i64 %33, 1
%44 = icmp eq i64 %43, 256
br i1 %44, label %45, label %32
45: ; preds = %42
%46 = tail call i32 @exit(i32 0)
unreachable
}