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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int gfd, i, result, len;
  unsigned char buffer[4096];
  if (argc != 2) {
    fprintf(stderr, "Usage: rawdump raw-data-file\n");
    exit(1);
  }
  gfd = open(argv[1], O_RDONLY);
  result = 1;
  while (result > 0) {
    result = read(gfd, &len, sizeof(len));
    if (result > 0) {
      result = read(gfd, buffer, len);
      if (result > 0) {
        printf("%3d:", len);
        for (i = 0; i < (len / 1); ++i)
          printf(" %2.2x", buffer[i]);
        printf("\n");
      }
    }
  }
  close(gfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a2 <main+0x42>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1289 <main+0x129>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1284 <main+0x124>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    127f <main+0x11f>
mov    -0x20(%rbp),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1024(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1024(%rbp),%eax
cmp    %ecx,%eax
jge    1271 <main+0x111>
movslq -0x18(%rbp),%rax
movzbl -0x1020(%rbp,%rax,1),%esi
ff
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1225 <main+0xc5>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1284 <main+0x124>
jmp    11c2 <main+0x62>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
cmp    $0x2,%edi
jne    125c <main+0xec>
mov    0x8(%rsi),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%r13d
lea    0xc(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xe73(%rip),%rbx
jmp    11ce <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
jle    1240 <main+0xd0>
mov    $0x4,%edx
mov    %r13d,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <read@plt>
test   %eax,%eax
jle    1240 <main+0xd0>
mov    0xc(%rsp),%edx
mov    %r13d,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <read@plt>
test   %eax,%eax
jle    1240 <main+0xd0>
mov    %eax,%ebp
mov    0xc(%rsp),%esi
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11c0 <main+0x50>
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movzbl 0x10(%rsp,%r12,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12
movslq 0xc(%rsp),%rax
cmp    %rax,%r12
jl     1220 <main+0xb0>
jmp    11c0 <main+0x50>
mov    %r13d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: rawdump raw-data-file\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"%3d:\00"
@.str.2 = [7 x i8] c" %2.2x\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %14, i32 %15)
br label %17
17: ; preds = %12, %39
%18 = call i32 (i32, ...) @read(i32 %16, i32* %3, i64 4)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %42
20: ; preds = %17
%21 = load i32, i32* %3
%22 = call i32 (i32, ...) @read(i32 %16, i8* %6, i32 %21)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %20
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %3
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %24, %29
%30 = phi i64 [ %35, %29 ], [ 0, %24 ]
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i64 %30, 1
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %29, label %39
39: ; preds = %29, %24
%40 = call i32 @putchar(i32 10)
%41 = icmp sgt i32 %22, 0
br i1 %41, label %17, label %42
42: ; preds = %17, %20, %39
%43 = call i32 @close(i32 %16)
ret i32 0
}