#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 */
scalar_t__ ReadLog(int /*<<< orphan*/, size_t *, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ getopt(int, char **, char const *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, char, char);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  size_t bytes;
  char *data = 0;
  char *outputfilename;
  const char *optstring = "hv";
  int blockno = 0;
  FILE *outputfile;
  while (getopt(argc, argv, optstring) > 0) {
  }
  outputfilename = (char *)malloc(2048);
  data = (char *)malloc(32768);
  while (ReadLog(stdin, &bytes, data)) {
    printf("Block[%.4d]: %x %x\n", blockno, data[0], data[1]);
    sprintf(outputfilename, "%s_%.4d.raw", argv[1], blockno);
    outputfile = fopen(outputfilename, "w");
    fwrite(data, 1, bytes, outputfile);
    blockno++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe6b(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <getopt@plt>
cmp    $0x0,%rax
jle    11bf <main+0x4f>
jmp    11a0 <main+0x30>
mov    $0x800,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x8000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1070 <ReadLog@plt>
cmp    $0x0,%rax
je     126e <main+0xfe>
mov    -0x34(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
lea    0xdf4(%rip),%rdi
movsbl %cl,%edx
movsbl 0x1(%rax),%ecx
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x34(%rbp),%ecx
lea    0xde6(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11db <main+0x6b>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xe79(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1060 <getopt@plt>
test   %rax,%rax
jg     1190 <main+0x20>
mov    $0x800,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x8000,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    %rbx,%rdx
call   1070 <ReadLog@plt>
test   %rax,%rax
je     1255 <main+0xe5>
xor    %ebp,%ebp
lea    0xe3f(%rip),%r12
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%rbx),%edx
movsbl 0x1(%rbx),%ecx
lea    0xe05(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    0x8(%r15),%rdx
mov    %r14,%rdi
lea    0xe04(%rip),%rsi
mov    %ebp,%ecx
call   1080 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <fopen@plt>
mov    (%rsp),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1090 <fwrite@plt>
add    $0x1,%ebp
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1070 <ReadLog@plt>
test   %rax,%rax
jne    11f0 <main+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"hv\00"
@stdin = global i32 0
@.str.1 = [20 x i8] c"Block[%.4d]: %x %x\0A\00"
@.str.2 = [12 x i8] c"%s_%.4d.raw\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %9
store i32 0, i32* %10
br label %12
12: ; preds = %18, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = load i8*, i8** %9
%16 = call i64 @getopt(i32 %13, i8** %14, i8* %15)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
br label %12
19: ; preds = %12
%20 = call i64 @malloc(i32 2048)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %8
%22 = call i64 @malloc(i32 32768)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %7
br label %24
24: ; preds = %29, %19
%25 = load i32, i32* @stdin
%26 = load i8*, i8** %7
%27 = call i64 @ReadLog(i32 %25, i64* %6, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %52
29: ; preds = %24
%30 = load i32, i32* %10
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8 signext %33, i8 signext %36)
%38 = load i8*, i8** %8
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i32, i32* %10
%43 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %41, i32 %42)
%44 = load i8*, i8** %8
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %45, i32** %11
%46 = load i8*, i8** %7
%47 = load i64, i64* %6
%48 = load i32*, i32** %11
%49 = call i32 @fwrite(i8* %46, i32 1, i64 %47, i32* %48)
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %24
52: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"hv\00"
@stdin = global i32 0
@.str.1 = [20 x i8] c"Block[%.4d]: %x %x\0A\00"
@.str.2 = [12 x i8] c"%s_%.4d.raw\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
br label %5
5: ; preds = %5, %2
%6 = tail call i64 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i64 %6, 0
br i1 %7, label %5, label %8
8: ; preds = %5
%9 = tail call i64 @malloc(i32 2048)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i64 @malloc(i32 32768)
%12 = inttoptr i64 %11 to i8*
%13 = load i32, i32* @stdin
%14 = call i64 @ReadLog(i32 %13, i64* %3, i8* %12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %33, label %16
16: ; preds = %8
%17 = getelementptr inbounds i8, i8* %12, i64 1
%18 = getelementptr inbounds i8*, i8** %1, i64 1
br label %19
19: ; preds = %16, %19
%20 = phi i32 [ 0, %16 ], [ %29, %19 ]
%21 = load i8, i8* %12
%22 = load i8, i8* %17
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8 signext %21, i8 signext %22)
%24 = load i8*, i8** %18
%25 = call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32 %20)
%26 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%27 = load i64, i64* %3
%28 = call i32 @fwrite(i8* %12, i32 1, i64 %27, i32* %26)
%29 = add nuw nsw i32 %20, 1
%30 = load i32, i32* @stdin
%31 = call i64 @ReadLog(i32 %30, i64* %3, i8* %12)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %19
33: ; preds = %19, %8
ret i32 0
}