#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 */
char EOF;
char getchar();
int /*<<< orphan*/ isgraph(char);
int /*<<< orphan*/ putchar(char);
int sprintf(char *, char *, char);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char c;
  char *option;
  char *format;
  char string[10];
  int state, position, count, i;
  position = 0;
  option = *++argv;
  if (argc == 1) {
    return 1;
  } else {
    if (strcmp(option, "oct") == 0) {
      format = "%o";
    } else {
      format = "%x";
    }
  }
  while ((c = getchar()) != EOF) {
    if (!isgraph(c)) {
      count = sprintf(string, format, c);
      for (i = 0; i < count; i++) {
        if (position == 10) {
          putchar('\n');
          position = 0;
        }
        putchar(*(string + i));
        ++position;
      }
    } else {
      if (position == 10) {
        putchar('\n');
        position = 0;
      }
      putchar(c);
      ++position;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    119a <main+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    12af <main+0x15f>
mov    -0x20(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c4 <main+0x74>
lea    0xe49(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11cf <main+0x7f>
lea    0xe3c(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11d4 <main+0x84>
jmp    11d9 <main+0x89>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2dfb(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12a8 <main+0x158>
movsbl -0x11(%rbp),%edi
call   1070 <isgraph@plt>
cmp    $0x0,%eax
jne    1276 <main+0x126>
lea    -0x32(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movsbl -0x11(%rbp),%edx
call   1060 <sprintf@plt>
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    1271 <main+0x121>
cmpl   $0xa,-0x3c(%rbp)
jne    124c <main+0xfc>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x3c(%rbp)
movslq -0x44(%rbp),%rax
movsbl -0x32(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1225 <main+0xd5>
jmp    12a3 <main+0x153>
cmpl   $0xa,-0x3c(%rbp)
jne    1291 <main+0x141>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x3c(%rbp)
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d9 <main+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%ebp
cmp    $0x1,%edi
je     11a3 <main+0x53>
mov    0x8(%rsi),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
lea    0xe82(%rip),%rax
lea    0xe7e(%rip),%r15
cmove  %rax,%r15
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e4b(%rip),%r12
cmp    (%r12),%al
jne    11b4 <main+0x64>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
lea    0xe(%rsp),%r14
jmp    11d9 <main+0x89>
nopl   (%rax)
mov    %ebp,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r12),%al
je     11a3 <main+0x53>
movsbl %al,%ebp
mov    %ebp,%edi
call   1070 <isgraph@plt>
test   %eax,%eax
je     1200 <main+0xb0>
cmp    $0xa,%ebx
jne    11c0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
jmp    11c0 <main+0x70>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <sprintf@plt>
test   %eax,%eax
jle    11ca <main+0x7a>
mov    %eax,%r13d
xor    %ebp,%ebp
jmp    1236 <main+0xe6>
nopl   0x0(%rax,%rax,1)
movsbl 0xe(%rsp,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
add    $0x1,%rbp
cmp    %rbp,%r13
je     11ca <main+0x7a>
cmp    $0xa,%ebx
jne    1220 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
jmp    1220 <main+0xd0>

LLVM IR (-O0):
@.str = [4 x i8] c"oct\00"
@.str.1 = [3 x i8] c"%o\00"
@.str.2 = [3 x i8] c"%x\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [10 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i32 1
store i8** %15, i8*** %5
%16 = load i8*, i8** %15
store i8* %16, i8** %7
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 1, i32* %3
br label %77
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %26
25: ; preds = %20
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %26
26: ; preds = %25, %24
br label %27
27: ; preds = %26
br label %28
28: ; preds = %75, %27
%29 = call signext i8 (...) @getchar()
store i8 %29, i8* %6
%30 = sext i8 %29 to i32
%31 = load i8, i8* @EOF
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %76
34: ; preds = %28
%35 = load i8, i8* %6
%36 = call i32 @isgraph(i8 signext %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %65, label %38
38: ; preds = %34
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%40 = load i8*, i8** %8
%41 = load i8, i8* %6
%42 = call i32 @sprintf(i8* %39, i8* %40, i8 signext %41)
store i32 %42, i32* %12
store i32 0, i32* %13
br label %43
43: ; preds = %61, %38
%44 = load i32, i32* %13
%45 = load i32, i32* %12
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %64
47: ; preds = %43
%48 = load i32, i32* %11
%49 = icmp eq i32 %48, 10
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %11
br label %52
52: ; preds = %50, %47
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%54 = load i32, i32* %13
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = call i32 @putchar(i8 signext %57)
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
store i32 %60, i32* %11
br label %61
61: ; preds = %52
%62 = load i32, i32* %13
%63 = add nsw i32 %62, 1
store i32 %63, i32* %13
br label %43
64: ; preds = %43
br label %75
65: ; preds = %34
%66 = load i32, i32* %11
%67 = icmp eq i32 %66, 10
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %11
br label %70
70: ; preds = %68, %65
%71 = load i8, i8* %6
%72 = call i32 @putchar(i8 signext %71)
%73 = load i32, i32* %11
%74 = add nsw i32 %73, 1
store i32 %74, i32* %11
br label %75
75: ; preds = %70, %64
br label %28
76: ; preds = %28
store i32 0, i32* %3
br label %77
77: ; preds = %76, %19
%78 = load i32, i32* %3
ret i32 %78
}

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