#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 /*<<< orphan*/ convertFromAscii(char *, int);
int /*<<< orphan*/ convertToAscii(char *, int);
int getopt(int, char **, char *);
int /*<<< orphan*/ noArgument(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ showUsage(char *);
scalar_t__ strcmp(char *, char *);
void oct2ascii(int argc, char **argv, char *applet) {
  int opt = 0;
  bool reverse = false;
  bool pr_help = false;
  while ((opt = getopt(argc, argv, "rh")) != -1) {
    switch (opt) {
    case 'r':
      reverse = true;
      break;
    case 'h':
      pr_help = true;
      break;
    }
  }
  if (!pr_help) {
    if (reverse) {
      if (argc > 2) {
        printf("OCT: ");
      } else {
        noArgument(applet);
      }
    } else {
      if (argc > 1) {
        printf("ASCII: ");
      } else {
        noArgument(applet);
      }
    }
    for (int i = 1; i < argc; i++) {
      if (reverse) {
        if (strcmp(argv[i], "-r") == 0) {
          continue;
        }
        convertFromAscii(argv[i], 8);
      } else {
        convertToAscii(argv[i], 8);
      }
    }
    printf("\n");
  } else {
    showUsage(applet);
  }
}


x86 assembly (clang, -O0):
<oct2ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5a(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11f4 <oct2ascii+0x84>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x68,%eax
je     11e8 <oct2ascii+0x78>
jmp    11cb <oct2ascii+0x5b>
mov    -0x2c(%rbp),%eax
sub    $0x72,%eax
jne    11ef <oct2ascii+0x7f>
jmp    11dc <oct2ascii+0x6c>
movl   $0x1,-0x20(%rbp)
jmp    11ef <oct2ascii+0x7f>
movl   $0x1,-0x24(%rbp)
jmp    1198 <oct2ascii+0x28>
cmpl   $0x0,-0x24(%rbp)
jne    12f3 <oct2ascii+0x183>
cmpl   $0x0,-0x20(%rbp)
je     1231 <oct2ascii+0xc1>
cmpl   $0x2,-0x4(%rbp)
jle    1223 <oct2ascii+0xb3>
lea    0xdea(%rip),%rdi
call   1050 <printf@plt>
jmp    122c <oct2ascii+0xbc>
mov    -0x18(%rbp),%rdi
call   1090 <noArgument@plt>
jmp    125a <oct2ascii+0xea>
cmpl   $0x1,-0x4(%rbp)
jle    124c <oct2ascii+0xdc>
lea    0xdc7(%rip),%rdi
call   1050 <printf@plt>
jmp    1255 <oct2ascii+0xe5>
mov    -0x18(%rbp),%rdi
call   1090 <noArgument@plt>
jmp    125a <oct2ascii+0xea>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12e2 <oct2ascii+0x172>
cmpl   $0x0,-0x20(%rbp)
je     12b9 <oct2ascii+0x149>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd87(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    129e <oct2ascii+0x12e>
jmp    12d4 <oct2ascii+0x164>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x8,%esi
call   1070 <convertFromAscii@plt>
jmp    12cf <oct2ascii+0x15f>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x8,%esi
call   1030 <convertToAscii@plt>
jmp    12d4 <oct2ascii+0x164>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1261 <oct2ascii+0xf1>
lea    0xd2b(%rip),%rdi
call   1050 <printf@plt>
jmp    12fc <oct2ascii+0x18c>
mov    -0x18(%rbp),%rdi
call   1040 <showUsage@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oct2ascii>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r13d,%r13d
mov    $0x1,%r12b
lea    0xe60(%rip),%r15
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
cmp    $0x72,%eax
je     11be <oct2ascii+0x3e>
cmp    $0x68,%eax
je     11c3 <oct2ascii+0x43>
cmp    $0xffffffff,%eax
jne    11a0 <oct2ascii+0x20>
jmp    11cb <oct2ascii+0x4b>
xor    %r12d,%r12d
jmp    11a0 <oct2ascii+0x20>
mov    $0x1,%r13d
jmp    11a0 <oct2ascii+0x20>
test   %r13d,%r13d
je     11e6 <oct2ascii+0x66>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <showUsage@plt>
test   $0x1,%r12b
je     11fa <oct2ascii+0x7a>
cmp    $0x1,%ebp
jle    120d <oct2ascii+0x8d>
lea    0xe11(%rip),%rdi
jmp    1206 <oct2ascii+0x86>
cmp    $0x2,%ebp
jle    1217 <oct2ascii+0x97>
lea    0xdfd(%rip),%rdi
call   1060 <printf@plt>
jmp    1224 <oct2ascii+0xa4>
mov    %r14,%rdi
call   10a0 <noArgument@plt>
jmp    127a <oct2ascii+0xfa>
mov    %r14,%rdi
call   10a0 <noArgument@plt>
cmp    $0x2,%ebp
jne    127a <oct2ascii+0xfa>
mov    %ebp,%r15d
mov    $0x1,%ebp
lea    0xdde(%rip),%r14
jmp    1253 <oct2ascii+0xd3>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x8,%esi
call   1040 <convertToAscii@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
je     127a <oct2ascii+0xfa>
mov    (%rbx,%rbp,8),%rdi
test   $0x1,%r12b
jne    1240 <oct2ascii+0xc0>
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     124a <oct2ascii+0xca>
mov    (%rbx,%rbp,8),%rdi
mov    $0x8,%esi
call   1080 <convertFromAscii@plt>
jmp    124a <oct2ascii+0xca>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rh\00"
@.str.1 = [6 x i8] c"OCT: \00"
@.str.2 = [8 x i8] c"ASCII: \00"
@.str.3 = [3 x i8] c"-r\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @oct2ascii(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %20, %3
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %7
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* %7
switch i32 %17, label %20 [
i32 114, label %18
i32 104, label %19
]
18: ; preds = %16
store i32 1, i32* %8
br label %20
19: ; preds = %16
store i32 1, i32* %9
br label %20
20: ; preds = %16, %19, %18
br label %11
21: ; preds = %11
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %82, label %24
24: ; preds = %21
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 2
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %35
32: ; preds = %27
%33 = load i8*, i8** %6
%34 = call i32 @noArgument(i8* %33)
br label %35
35: ; preds = %32, %30
br label %45
36: ; preds = %24
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %44
41: ; preds = %36
%42 = load i8*, i8** %6
%43 = call i32 @noArgument(i8* %42)
br label %44
44: ; preds = %41, %39
br label %45
45: ; preds = %44, %35
store i32 1, i32* %10
br label %46
46: ; preds = %77, %45
%47 = load i32, i32* %10
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %80
50: ; preds = %46
%51 = load i32, i32* %8
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %69
53: ; preds = %50
%54 = load i8**, i8*** %5
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %53
br label %77
62: ; preds = %53
%63 = load i8**, i8*** %5
%64 = load i32, i32* %10
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %63, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 @convertFromAscii(i8* %67, i32 8)
br label %76
69: ; preds = %50
%70 = load i8**, i8*** %5
%71 = load i32, i32* %10
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8*, i8** %70, i64 %72
%74 = load i8*, i8** %73
%75 = call i32 @convertToAscii(i8* %74, i32 8)
br label %76
76: ; preds = %69, %62
br label %77
77: ; preds = %76, %61
%78 = load i32, i32* %10
%79 = add nsw i32 %78, 1
store i32 %79, i32* %10
br label %46
80: ; preds = %46
%81 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %85
82: ; preds = %21
%83 = load i8*, i8** %6
%84 = call i32 @showUsage(i8* %83)
br label %85
85: ; preds = %82, %80
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rh\00"
@.str.1 = [6 x i8] c"OCT: \00"
@.str.2 = [8 x i8] c"ASCII: \00"
@.str.3 = [3 x i8] c"-r\00"
define void @oct2ascii(i32 %0, i8** %1, i8* %2) {
br label %4
4: ; preds = %9, %3
%5 = phi i1 [ true, %3 ], [ false, %9 ]
%6 = phi i32 [ 0, %3 ], [ %8, %9 ]
br label %7
7: ; preds = %9, %4
%8 = phi i32 [ %6, %4 ], [ 1, %9 ]
br label %9
9: ; preds = %7, %9
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %10, label %9 [
i32 -1, label %11
i32 114, label %4
i32 104, label %7
]
11: ; preds = %9
%12 = icmp eq i32 %8, 0
br i1 %12, label %13, label %45
13: ; preds = %11
br i1 %5, label %16, label %14
14: ; preds = %13
%15 = icmp sgt i32 %0, 2
br i1 %15, label %23, label %20
16: ; preds = %13
%17 = icmp sgt i32 %0, 1
br i1 %17, label %23, label %18
18: ; preds = %16
%19 = tail call i32 @noArgument(i8* %2)
br label %28
20: ; preds = %14
%21 = tail call i32 @noArgument(i8* %2)
%22 = icmp eq i32 %0, 2
br i1 %22, label %26, label %28
23: ; preds = %16, %14
%24 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %14 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %16 ]
%25 = tail call i32 @printf(i8* dereferenceable(1) %24)
br label %26
26: ; preds = %23, %20
%27 = zext i32 %0 to i64
br label %30
28: ; preds = %42, %18, %20
%29 = tail call i32 @putchar(i32 10)
br label %47
30: ; preds = %26, %42
%31 = phi i64 [ 1, %26 ], [ %43, %42 ]
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
br i1 %5, label %40, label %34
34: ; preds = %30
%35 = tail call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %34
%38 = load i8*, i8** %32
%39 = tail call i32 @convertFromAscii(i8* %38, i32 8)
br label %42
40: ; preds = %30
%41 = tail call i32 @convertToAscii(i8* %33, i32 8)
br label %42
42: ; preds = %37, %40, %34
%43 = add nuw nsw i64 %31, 1
%44 = icmp eq i64 %43, %27
br i1 %44, label %28, label %30
45: ; preds = %11
%46 = tail call i32 @showUsage(i8* %2)
br label %47
47: ; preds = %45, %28
ret void
}