#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(unsigned char *);
int getblk(unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int main() {
  unsigned char *buf;
  buf = (unsigned char *)malloc((1024 * 1024));
  if (buf == NULL) {
    fprintf(stderr, "main: out of memory "
                    "allocating buf\n");
    exit(1);
  }
  while (1) {
    int blklen;
    char topstr[128];
    char botstr[128];
    char *topp;
    char *topq;
    char *botp;
    char *p, *q;
    blklen = getblk(buf);
    if (blklen == EOF)
      break;
    p = (char *)buf;
    q = (char *)buf + blklen;
    while (p < q) {
      topp = (char *)topstr;
      topq = (char *)topstr + 72;
      botp = (char *)botstr;
      while (topp < topq) {
        *topp++ = *p++;
        *botp++ = *p++;
      }
      *topp = '\0';
      *botp = '\0';
      printf("%s\n%s\n--------\n", topstr, botstr);
    }
  }
  free(buf);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11aa <main+0x4a>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11af <main+0x4f>
mov    -0x10(%rbp),%rdi
call   1080 <getblk@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%eax
jne    11d2 <main+0x72>
jmp    12de <main+0x17e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x148(%rbp)
mov    -0x140(%rbp),%rax
cmp    -0x148(%rbp),%rax
jae    12d9 <main+0x179>
lea    -0xa0(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0xa0(%rbp),%rax
add    $0x48,%rax
mov    %rax,-0x130(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x128(%rbp),%rax
cmp    -0x130(%rbp),%rax
jae    12a6 <main+0x146>
mov    -0x140(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x140(%rbp)
mov    (%rax),%cl
mov    -0x128(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x128(%rbp)
mov    %cl,(%rax)
mov    -0x140(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x140(%rbp)
mov    (%rax),%cl
mov    -0x138(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x138(%rbp)
mov    %cl,(%rax)
jmp    1231 <main+0xd1>
mov    -0x128(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x138(%rbp),%rax
movb   $0x0,(%rax)
lea    -0xa0(%rbp),%rsi
lea    -0x120(%rbp),%rdx
lea    0xd55(%rip),%rdi
call   1040 <printf@plt>
jmp    11ef <main+0x8f>
jmp    11af <main+0x4f>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    $0x100000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1250 <main+0xf0>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <getblk@plt>
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
jne    11b6 <main+0x56>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x58(%rsp),%rbp
lea    0x2(%r14),%rcx
mov    %rcx,0x8(%rsp)
lea    0x90(%rsp),%r15
lea    0x10(%rsp),%rbx
lea    0xe4c(%rip),%r12
mov    %r14,(%rsp)
jmp    11f7 <main+0x97>
xchg   %ax,%ax
mov    (%rsp),%r14
mov    %r14,%rdi
call   1080 <getblk@plt>
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%eax
je     119a <main+0x3a>
test   %eax,%eax
jle    11e0 <main+0x80>
movslq %eax,%r13
add    (%rsp),%r13
mov    0x8(%rsp),%r14
mov    %r15,%rax
mov    %rbx,%rcx
jmp    1214 <main+0xb4>
nop
add    $0x2,%r14
movzbl -0x2(%r14),%edx
mov    %dl,(%rcx)
add    $0x1,%rcx
movzbl -0x1(%r14),%edx
mov    %dl,(%rax)
add    $0x1,%rax
cmp    %rbp,%rcx
jb     1210 <main+0xb0>
movb   $0x0,(%rcx)
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <printf@plt>
mov    %r15,%rax
mov    %rbx,%rcx
cmp    %r13,%r14
jb     1210 <main+0xb0>
jmp    11e0 <main+0x80>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"main: out of memory allocating buf\0A\00"
@EOF = global i32 0
@.str.1 = [16 x i8] c"%s\0A%s\0A--------\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca [128 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %1
%11 = call i64 @malloc(i32 1048576)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
br label %20
20: ; preds = %19, %63
%21 = load i8*, i8** %2
%22 = call i32 @getblk(i8* %21)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %20
br label %64
27: ; preds = %20
%28 = load i8*, i8** %2
store i8* %28, i8** %9
%29 = load i8*, i8** %2
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8* %32, i8** %10
br label %33
33: ; preds = %57, %27
%34 = load i8*, i8** %9
%35 = load i8*, i8** %10
%36 = icmp ult i8* %34, %35
br i1 %36, label %37, label %63
37: ; preds = %33
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
store i8* %38, i8** %6
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%40 = getelementptr inbounds i8, i8* %39, i64 72
store i8* %40, i8** %7
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
store i8* %41, i8** %8
br label %42
42: ; preds = %46, %37
%43 = load i8*, i8** %6
%44 = load i8*, i8** %7
%45 = icmp ult i8* %43, %44
br i1 %45, label %46, label %57
46: ; preds = %42
%47 = load i8*, i8** %9
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %9
%49 = load i8, i8* %47
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %6
store i8 %49, i8* %50
%52 = load i8*, i8** %9
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %9
%54 = load i8, i8* %52
%55 = load i8*, i8** %8
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %8
store i8 %54, i8* %55
br label %42
57: ; preds = %42
%58 = load i8*, i8** %6
store i8 0, i8* %58
%59 = load i8*, i8** %8
store i8 0, i8* %59
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%62 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %60, i8* %61)
br label %33
63: ; preds = %33
br label %20
64: ; preds = %26
%65 = load i8*, i8** %2
%66 = call i32 @free(i8* %65)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"main: out of memory allocating buf\0A\00"
@EOF = global i32 0
@.str.1 = [16 x i8] c"%s\0A%s\0A--------\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = tail call i64 @malloc(i32 1048576)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %14, label %6
6: ; preds = %0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%9 = call i32 @getblk(i8* %4)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %44, label %12
12: ; preds = %6
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 72
br label %18
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12, %40
%19 = phi i32 [ %9, %12 ], [ %41, %40 ]
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %4, i64 %20
%22 = icmp sgt i32 %19, 0
br i1 %22, label %23, label %40
23: ; preds = %18, %34
%24 = phi i8* [ %30, %34 ], [ %4, %18 ]
%25 = phi i8* [ %35, %34 ], [ %8, %18 ]
%26 = phi i8* [ %36, %34 ], [ %7, %18 ]
%27 = getelementptr inbounds i8, i8* %24, i64 1
%28 = load i8, i8* %24
%29 = getelementptr inbounds i8, i8* %26, i64 1
store i8 %28, i8* %26
%30 = getelementptr inbounds i8, i8* %24, i64 2
%31 = load i8, i8* %27
%32 = getelementptr inbounds i8, i8* %25, i64 1
store i8 %31, i8* %25
%33 = icmp ult i8* %29, %13
br i1 %33, label %34, label %37
34: ; preds = %23, %37
%35 = phi i8* [ %32, %23 ], [ %8, %37 ]
%36 = phi i8* [ %29, %23 ], [ %7, %37 ]
br label %23
37: ; preds = %23
store i8 0, i8* %29
store i8 0, i8* %32
%38 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %8)
%39 = icmp ult i8* %30, %21
br i1 %39, label %34, label %40
40: ; preds = %37, %18
%41 = call i32 @getblk(i8* %4)
%42 = load i32, i32* @EOF
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %18
44: ; preds = %40, %6
%45 = call i32 @free(i8* %4)
ret i32 0
}