#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*/ ProcessArgs(int, char **, int *);
scalar_t__ can_print(int);
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int main(int argc, char *argv[]) {
  int split = 80;
  int output = 16;
  int ch;
  int textrun = 0;
  int binaryrun = 0;
  char *format;
  int width = 0;
  ProcessArgs(argc, argv, &output);
  if (output == 16) {
    format = "%02X ";
    width = 4;
  } else {
    format = "%3o ";
    width = 4;
  }
  while ((ch = getchar()) != EOF) {
    if (can_print(ch)) {
      if (binaryrun > 0) {
        putchar('\n');
        binaryrun = 0;
        textrun = 0;
      }
      putchar(ch);
      ++textrun;
      if (ch == '\n') {
        textrun = 0;
      }
      if (textrun == split) {
        putchar('\n');
        textrun = 0;
      }
    } else {
      if (textrun > 0 || binaryrun + width >= split) {
        printf("\nBinary stream: ");
        textrun = 0;
        binaryrun = 15;
      }
      printf(format, ch);
      binaryrun += width;
    }
  }
  putchar('\n');
  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)
movl   $0x50,-0x14(%rbp)
movl   $0x10,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <ProcessArgs@plt>
cmpl   $0x10,-0x18(%rbp)
jne    11ba <main+0x6a>
lea    0xe56(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x4,-0x34(%rbp)
jmp    11cc <main+0x7c>
lea    0xe45(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x4,-0x34(%rbp)
jmp    11d1 <main+0x81>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%eax
je     12b6 <main+0x166>
mov    -0x1c(%rbp),%edi
call   1040 <can_print@plt>
cmp    $0x0,%rax
je     1265 <main+0x115>
cmpl   $0x0,-0x24(%rbp)
jle    121e <main+0xce>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    1243 <main+0xf3>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1260 <main+0x110>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x20(%rbp)
jmp    12b1 <main+0x161>
cmpl   $0x0,-0x20(%rbp)
jg     127e <main+0x12e>
mov    -0x24(%rbp),%eax
add    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     129a <main+0x14a>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x20(%rbp)
movl   $0xf,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x34(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11d1 <main+0x81>
mov    $0xa,%edi
call   1030 <putchar@plt>
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
movl   $0x10,0x4(%rsp)
lea    0x4(%rsp),%rdx
call   1050 <ProcessArgs@plt>
cmpl   $0x10,0x4(%rsp)
lea    0xe87(%rip),%rax
lea    0xe86(%rip),%r12
cmove  %rax,%r12
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2e53(%rip),%r13
cmp    0x0(%r13),%eax
jne    11b6 <main+0x66>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    11f4 <main+0xa4>
xor    %ebx,%ebx
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xf,%r14d
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x4,%r14d
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     119b <main+0x4b>
mov    %ebp,%edi
call   1040 <can_print@plt>
test   %rax,%rax
je     1240 <main+0xf0>
test   %r14d,%r14d
jle    1214 <main+0xc4>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
xor    %r14d,%r14d
movsbl %bpl,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    $0xa,%ebp
cmove  %r15d,%ebx
cmp    $0x50,%ebx
jne    11e5 <main+0x95>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
jmp    11e5 <main+0x95>
nopw   0x0(%rax,%rax,1)
test   %ebx,%ebx
jg     11bf <main+0x6f>
cmp    $0x4c,%r14d
jl     11d5 <main+0x85>
jmp    11bf <main+0x6f>

LLVM IR (-O0):
@.str = [6 x i8] c"%02X \00"
@.str.1 = [5 x i8] c"%3o \00"
@EOF = global i32 0
@.str.2 = [17 x i8] c"\0ABinary stream: \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 i32
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 80, i32* %6
store i32 16, i32* %7
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %12
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @ProcessArgs(i32 %13, i8** %14, i32* %7)
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 16
br i1 %17, label %18, label %19
18: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %11
store i32 4, i32* %12
br label %20
19: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %11
store i32 4, i32* %12
br label %20
20: ; preds = %19, %18
br label %21
21: ; preds = %68, %20
%22 = call i32 (...) @getchar()
store i32 %22, i32* %8
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %69
25: ; preds = %21
%26 = load i32, i32* %8
%27 = call i64 @can_print(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %50
29: ; preds = %25
%30 = load i32, i32* %10
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %10
store i32 0, i32* %9
br label %34
34: ; preds = %32, %29
%35 = load i32, i32* %8
%36 = trunc i32 %35 to i8
%37 = call i32 @putchar(i8 signext %36)
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, 10
br i1 %41, label %42, label %43
42: ; preds = %34
store i32 0, i32* %9
br label %43
43: ; preds = %42, %34
%44 = load i32, i32* %9
%45 = load i32, i32* %6
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %9
br label %49
49: ; preds = %47, %43
br label %68
50: ; preds = %25
%51 = load i32, i32* %9
%52 = icmp sgt i32 %51, 0
br i1 %52, label %59, label %53
53: ; preds = %50
%54 = load i32, i32* %10
%55 = load i32, i32* %12
%56 = add nsw i32 %54, %55
%57 = load i32, i32* %6
%58 = icmp sge i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %53, %50
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
store i32 15, i32* %10
br label %61
61: ; preds = %59, %53
%62 = load i8*, i8** %11
%63 = load i32, i32* %8
%64 = call i32 (i8*, ...) @printf(i8* %62, i32 %63)
%65 = load i32, i32* %12
%66 = load i32, i32* %10
%67 = add nsw i32 %66, %65
store i32 %67, i32* %10
br label %68
68: ; preds = %61, %49
br label %21
69: ; preds = %21
%70 = call i32 @putchar(i8 signext 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%02X \00"
@.str.1 = [5 x i8] c"%3o \00"
@EOF = global i32 0
@.str.2 = [17 x i8] c"\0ABinary stream: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 16, i32* %3
%5 = call i32 @ProcessArgs(i32 %0, i8** %1, i32* %3)
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 16
%8 = select i1 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%9 = call i32 (...) @getchar()
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %50, label %12
12: ; preds = %2, %44
%13 = phi i32 [ %47, %44 ], [ %9, %2 ]
%14 = phi i32 [ %46, %44 ], [ 0, %2 ]
%15 = phi i32 [ %45, %44 ], [ 0, %2 ]
%16 = call i64 @can_print(i32 %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %33, label %18
18: ; preds = %12
%19 = icmp sgt i32 %14, 0
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = call i32 @putchar(i8 signext 10)
br label %22
22: ; preds = %20, %18
%23 = phi i32 [ 0, %20 ], [ %15, %18 ]
%24 = phi i32 [ 0, %20 ], [ %14, %18 ]
%25 = trunc i32 %13 to i8
%26 = call i32 @putchar(i8 signext %25)
%27 = add nsw i32 %23, 1
%28 = icmp eq i32 %13, 10
%29 = select i1 %28, i32 0, i32 %27
%30 = icmp eq i32 %29, 80
br i1 %30, label %31, label %44
31: ; preds = %22
%32 = call i32 @putchar(i8 signext 10)
br label %44
33: ; preds = %12
%34 = icmp sgt i32 %15, 0
%35 = icmp sgt i32 %14, 75
%36 = select i1 %34, i1 true, i1 %35
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %33, %37
%40 = phi i32 [ 0, %37 ], [ %15, %33 ]
%41 = phi i32 [ 15, %37 ], [ %14, %33 ]
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %8, i32 %13)
%43 = add nsw i32 %41, 4
br label %44
44: ; preds = %22, %31, %39
%45 = phi i32 [ 0, %31 ], [ %29, %22 ], [ %40, %39 ]
%46 = phi i32 [ %24, %31 ], [ %24, %22 ], [ %43, %39 ]
%47 = call i32 (...) @getchar()
%48 = load i32, i32* @EOF
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %12
50: ; preds = %44, %2
%51 = call i32 @putchar(i8 signext 10)
ret i32 0
}