#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 getchar();
int /*<<< orphan*/ iscntrl(int);
int /*<<< orphan*/ isprint(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  int c;
  short col = 0;
  if (argc < 2) {
    printf("No argument given\n");
    return 1;
  } else if (strcmp(argv[1], "hex") != 0 && strcmp(argv[1], "oct") != 0) {
    printf("Argument must be either 'hex' or 'oct'\n");
    return 1;
  }
  while ((c = getchar()) != EOF) {
    if (!isprint(c) && !iscntrl(c)) {
      if (strcmp(argv[1], "hex") == 0)
        printf("%#.2x", c);
      else
        printf("%#.3o", c);
      col += 4;
    } else {
      putchar(c);
      col++;
      if (col >= 80 - 8)
        col = 0, putchar('\n');
      if (c == '\n')
        col = 0;
      if (c == '\t')
        col += 8;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x0,-0x16(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a0 <main+0x40>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fa <main+0x19a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe64(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11f6 <main+0x96>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11f6 <main+0x96>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fa <main+0x19a>
jmp    11fb <main+0x9b>
jmp    1200 <main+0xa0>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%eax
je     12f3 <main+0x193>
mov    -0x14(%rbp),%edi
call   1080 <isprint@plt>
cmp    $0x0,%eax
jne    1290 <main+0x130>
mov    -0x14(%rbp),%edi
call   1040 <iscntrl@plt>
cmp    $0x0,%eax
jne    1290 <main+0x130>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc9(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    126f <main+0x10f>
mov    -0x14(%rbp),%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1280 <main+0x120>
mov    -0x14(%rbp),%esi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movswl -0x16(%rbp),%eax
add    $0x4,%eax
mov    %ax,-0x16(%rbp)
jmp    12ee <main+0x18e>
mov    -0x14(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x16(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x16(%rbp)
movswl -0x16(%rbp),%eax
cmp    $0x48,%eax
jl     12c4 <main+0x164>
movw   $0x0,-0x16(%rbp)
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0xa,-0x14(%rbp)
jne    12d4 <main+0x174>
movw   $0x0,-0x16(%rbp)
cmpl   $0x9,-0x14(%rbp)
jne    12e9 <main+0x189>
movswl -0x16(%rbp),%eax
add    $0x8,%eax
mov    %ax,-0x16(%rbp)
jmp    12ee <main+0x18e>
jmp    1200 <main+0xa0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jge    1189 <main+0x19>
lea    0xeb4(%rip),%rdi
jmp    11bd <main+0x4d>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe69(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11d8 <main+0x68>
mov    0x8(%r15),%rdi
lea    0xe58(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11d8 <main+0x68>
lea    0xe57(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0x2e00(%rip),%r12
cmp    (%r12),%eax
je     11c7 <main+0x57>
mov    %eax,%ebp
xor    %r13d,%r13d
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    1224 <main+0xb4>
nopw   0x0(%rax,%rax,1)
cmp    $0xa,%ebp
cmove  %r13d,%r14d
lea    0x8(%r14),%eax
cmp    $0x9,%ebp
cmovne %r14d,%eax
mov    %eax,%r14d
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %eax,%ebp
cmp    (%r12),%eax
je     11c7 <main+0x57>
mov    %ebp,%edi
call   1090 <isprint@plt>
test   %eax,%eax
jne    123a <main+0xca>
mov    %ebp,%edi
call   1050 <iscntrl@plt>
test   %eax,%eax
je     125d <main+0xed>
movsbl %bpl,%edi
call   1030 <putchar@plt>
add    $0x1,%r14d
cmp    $0x48,%r14w
jl     1200 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r14d,%r14d
jmp    1200 <main+0x90>
mov    0x8(%r15),%rdi
lea    0xd98(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
lea    0xd97(%rip),%rdi
lea    0xd8a(%rip),%rax
cmove  %rax,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x4,%r14d
jmp    1215 <main+0xa5>

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

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