#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 */
long long atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getopt(int, char **, char *);
int /*<<< orphan*/ help(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
long long myatoi(long long, char *);
int /*<<< orphan*/ myitoa(long long, long long, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  long long base, ibase, n;
  base = ibase = n = 0;
  char c;
  char ival[100];
  ibase = 10;
  int do1s, do2s;
  do1s = do2s = 0;
  while ((c = getopt(argc, argv, "ho:n:i:12")) != -1) {
    switch (c) {
    case 'o':
      base = atoi(optarg);
      break;
    case 'n':
      strcpy(ival, optarg);
      break;
    case 'i':
      ibase = atoi(optarg);
      break;
    case '1':
      do1s = 1;
      break;
    case '2':
      do2s = 1;
      break;
    case 'h':
      help(argv[0]);
      exit(0);
      break;
    default:
      usage(argv[0]);
      exit(0);
      break;
    }
  }
  if (argc < 5) {
    usage(argv[0]);
    exit(0);
  }
  if (base < 2 || base > 36) {
    usage(argv[0]);
    printf("base [%lld] out of range\n", base);
    exit(0);
  }
  if (ibase < 1 || ibase > 36) {
    usage(argv[0]);
    printf("inputbase [%lld] out of range\n", ibase);
    exit(0);
  }
  n = myatoi(ibase, ival);
  if (do1s)
    n = ~n;
  if (do2s)
    n = (~n) + 1;
  char buf[100];
  memset(buf, 0, 100);
  myitoa(base, n, buf);
  char *p = buf;
  while (*p == '0')
    ++p;
  printf("%s\n", p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0xa,-0x20(%rbp)
movl   $0x0,-0x98(%rbp)
movl   $0x0,-0x94(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe05(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x29(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     131c <main+0x17c>
movsbl -0x29(%rbp),%eax
mov    %eax,-0x10c(%rbp)
sub    $0x31,%eax
je     12d3 <main+0x133>
jmp    1227 <main+0x87>
mov    -0x10c(%rbp),%eax
sub    $0x32,%eax
je     12e2 <main+0x142>
jmp    123b <main+0x9b>
mov    -0x10c(%rbp),%eax
sub    $0x68,%eax
je     12f1 <main+0x151>
jmp    124f <main+0xaf>
mov    -0x10c(%rbp),%eax
sub    $0x69,%eax
je     12bc <main+0x11c>
jmp    1263 <main+0xc3>
mov    -0x10c(%rbp),%eax
sub    $0x6e,%eax
je     12a2 <main+0x102>
jmp    1277 <main+0xd7>
mov    -0x10c(%rbp),%eax
sub    $0x6f,%eax
jne    1304 <main+0x164>
jmp    128b <main+0xeb>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %rax,-0x18(%rbp)
jmp    1317 <main+0x177>
lea    -0x90(%rbp),%rdi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
call   1040 <strcpy@plt>
jmp    1317 <main+0x177>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %rax,-0x20(%rbp)
jmp    1317 <main+0x177>
movl   $0x1,-0x94(%rbp)
jmp    1317 <main+0x177>
movl   $0x1,-0x98(%rbp)
jmp    1317 <main+0x177>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <help@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    11ed <main+0x4d>
cmpl   $0x5,-0x8(%rbp)
jge    1339 <main+0x199>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
cmpq   $0x2,-0x18(%rbp)
jl     134f <main+0x1af>
cmpq   $0x24,-0x18(%rbp)
jle    1374 <main+0x1d4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    -0x18(%rbp),%rsi
lea    0xca9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
cmpq   $0x1,-0x20(%rbp)
jl     138a <main+0x1ea>
cmpq   $0x24,-0x20(%rbp)
jle    13af <main+0x20f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    -0x20(%rbp),%rsi
lea    0xc69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1030 <myatoi@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x94(%rbp)
je     13dc <main+0x23c>
mov    -0x28(%rbp),%rax
xor    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x98(%rbp)
je     13f9 <main+0x259>
mov    -0x28(%rbp),%rax
xor    $0xffffffffffffffff,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x100(%rbp),%rdx
call   1080 <myitoa@plt>
lea    -0x100(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1458 <main+0x2b8>
mov    -0x108(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x108(%rbp)
jmp    142e <main+0x28e>
mov    -0x108(%rbp),%rsi
lea    0xbc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe53(%rip),%rdx
call   10a0 <getopt@plt>
cmp    $0xff,%al
je     1284 <main+0xd4>
mov    $0xa,%ecx
mov    %rcx,0x10(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x8(%rsp)
lea    0xe2e(%rip),%r12
lea    0xe07(%rip),%r14
mov    0x2df8(%rip),%r15
xor    %r13d,%r13d
xor    %ecx,%ecx
mov    %rcx,0x18(%rsp)
jmp    122a <main+0x7a>
mov    (%r15),%edi
call   10c0 <atoi@plt>
mov    %rax,0x18(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10a0 <getopt@plt>
cmp    $0xff,%al
je     129f <main+0xef>
movsbl %al,%eax
lea    -0x68(%rax),%ecx
cmp    $0x7,%ecx
ja     1250 <main+0xa0>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
mov    (%r15),%edi
call   10c0 <atoi@plt>
mov    %rax,0x10(%rsp)
jmp    1219 <main+0x69>
nopl   (%rax)
cmp    $0x31,%eax
je     127c <main+0xcc>
cmp    $0x32,%eax
jne    1343 <main+0x193>
mov    $0x1,%eax
mov    %rax,0x8(%rsp)
jmp    1219 <main+0x69>
mov    (%r15),%esi
lea    0x90(%rsp),%rdi
call   1040 <strcpy@plt>
jmp    1219 <main+0x69>
mov    $0x1,%r13d
jmp    1219 <main+0x69>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    $0xa,%eax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
cmp    $0x4,%ebp
jle    1343 <main+0x193>
mov    0x18(%rsp),%r14
lea    -0x25(%r14),%rax
cmp    $0xffffffffffffffdc,%rax
mov    0x10(%rsp),%rbp
jbe    1361 <main+0x1b1>
lea    -0x25(%rbp),%rax
cmp    $0xffffffffffffffdb,%rax
jbe    1375 <main+0x1c5>
lea    0x90(%rsp),%rsi
mov    %rbp,%rdi
call   1030 <myatoi@plt>
neg    %r13d
sbb    %rcx,%rcx
xor    %rax,%rcx
mov    %rcx,%rbx
neg    %rbx
cmpl   $0x0,0x8(%rsp)
cmove  %rcx,%rbx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1070 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1090 <myitoa@plt>
lea    0x1f(%rsp),%rdi
nopl   (%rax)
cmpb   $0x30,0x1(%rdi)
lea    0x1(%rdi),%rdi
je     1320 <main+0x170>
call   1050 <puts@plt>
xor    %eax,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rdi
call   1080 <usage@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    (%rbx),%rdi
call   10b0 <help@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    (%rbx),%rdi
call   1080 <usage@plt>
lea    0xcbf(%rip),%rdi
mov    %r14,%rsi
jmp    1387 <main+0x1d7>
mov    (%rbx),%rdi
call   1080 <usage@plt>
lea    0xca6(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"ho:n:i:12\00"
@optarg = global i32 0
@.str.1 = [26 x i8] c"base [%lld] out of range\0A\00"
@.str.2 = [31 x i8] c"inputbase [%lld] out of range\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8
%10 = alloca [100 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca [100 x i8]
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
store i64 0, i64* %7
store i64 0, i64* %6
store i64 10, i64* %7
store i32 0, i32* %12
store i32 0, i32* %11
br label %15
15: ; preds = %48, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call signext i8 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8 %18, i8* %9
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %49
21: ; preds = %15
%22 = load i8, i8* %9
%23 = sext i8 %22 to i32
switch i32 %23, label %42 [
i32 111, label %24
i32 110, label %27
i32 105, label %31
i32 49, label %34
i32 50, label %35
i32 104, label %36
]
24: ; preds = %21
%25 = load i32, i32* @optarg
%26 = call i64 @atoi(i32 %25)
store i64 %26, i64* %6
br label %48
27: ; preds = %21
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%29 = load i32, i32* @optarg
%30 = call i32 @strcpy(i8* %28, i32 %29)
br label %48
31: ; preds = %21
%32 = load i32, i32* @optarg
%33 = call i64 @atoi(i32 %32)
store i64 %33, i64* %7
br label %48
34: ; preds = %21
store i32 1, i32* %11
br label %48
35: ; preds = %21
store i32 1, i32* %12
br label %48
36: ; preds = %21
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @help(i8* %39)
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %21
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = call i32 @usage(i8* %45)
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %35, %34, %31, %27, %24
br label %15
49: ; preds = %15
%50 = load i32, i32* %4
%51 = icmp slt i32 %50, 5
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = call i32 @usage(i8* %55)
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %49
%59 = load i64, i64* %6
%60 = icmp slt i64 %59, 2
br i1 %60, label %64, label %61
61: ; preds = %58
%62 = load i64, i64* %6
%63 = icmp sgt i64 %62, 36
br i1 %63, label %64, label %72
64: ; preds = %61, %58
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 0
%67 = load i8*, i8** %66
%68 = call i32 @usage(i8* %67)
%69 = load i64, i64* %6
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %69)
%71 = call i32 @exit(i32 0)
unreachable
72: ; preds = %61
%73 = load i64, i64* %7
%74 = icmp slt i64 %73, 1
br i1 %74, label %78, label %75
75: ; preds = %72
%76 = load i64, i64* %7
%77 = icmp sgt i64 %76, 36
br i1 %77, label %78, label %86
78: ; preds = %75, %72
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 0
%81 = load i8*, i8** %80
%82 = call i32 @usage(i8* %81)
%83 = load i64, i64* %7
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i64 %83)
%85 = call i32 @exit(i32 0)
unreachable
86: ; preds = %75
%87 = load i64, i64* %7
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%89 = call i64 @myatoi(i64 %87, i8* %88)
store i64 %89, i64* %8
%90 = load i32, i32* %11
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %86
%93 = load i64, i64* %8
%94 = xor i64 %93, -1
store i64 %94, i64* %8
br label %95
95: ; preds = %92, %86
%96 = load i32, i32* %12
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %102
98: ; preds = %95
%99 = load i64, i64* %8
%100 = xor i64 %99, -1
%101 = add nsw i64 %100, 1
store i64 %101, i64* %8
br label %102
102: ; preds = %98, %95
%103 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%104 = call i32 @memset(i8* %103, i32 0, i32 100)
%105 = load i64, i64* %6
%106 = load i64, i64* %8
%107 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%108 = call i32 @myitoa(i64 %105, i64 %106, i8* %107)
%109 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
store i8* %109, i8** %14
br label %110
110: ; preds = %115, %102
%111 = load i8*, i8** %14
%112 = load i8, i8* %111
%113 = sext i8 %112 to i32
%114 = icmp eq i32 %113, 48
br i1 %114, label %115, label %118
115: ; preds = %110
%116 = load i8*, i8** %14
%117 = getelementptr inbounds i8, i8* %116, i32 1
store i8* %117, i8** %14
br label %110
118: ; preds = %110
%119 = load i8*, i8** %14
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %119)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"ho:n:i:12\00"
@optarg = global i32 0
@.str.1 = [26 x i8] c"base [%lld] out of range\0A\00"
@.str.2 = [31 x i8] c"inputbase [%lld] out of range\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8 %6, -1
br i1 %7, label %40, label %8
8: ; preds = %2, %33
%9 = phi i8 [ %38, %33 ], [ %6, %2 ]
%10 = phi i32 [ %37, %33 ], [ 0, %2 ]
%11 = phi i32 [ %36, %33 ], [ 0, %2 ]
%12 = phi i64 [ %35, %33 ], [ 10, %2 ]
%13 = phi i64 [ %34, %33 ], [ 0, %2 ]
%14 = sext i8 %9 to i32
switch i32 %14, label %29 [
i32 111, label %15
i32 110, label %18
i32 105, label %21
i32 49, label %33
i32 50, label %24
i32 104, label %25
]
15: ; preds = %8
%16 = load i32, i32* @optarg
%17 = call i64 @atoi(i32 %16)
br label %33
18: ; preds = %8
%19 = load i32, i32* @optarg
%20 = call i32 @strcpy(i8* %5, i32 %19)
br label %33
21: ; preds = %8
%22 = load i32, i32* @optarg
%23 = call i64 @atoi(i32 %22)
br label %33
24: ; preds = %8
br label %33
25: ; preds = %8
%26 = load i8*, i8** %1
%27 = call i32 @help(i8* %26)
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %8
%30 = load i8*, i8** %1
%31 = call i32 @usage(i8* %30)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %8, %24, %21, %18, %15
%34 = phi i64 [ %13, %24 ], [ %13, %21 ], [ %13, %18 ], [ %17, %15 ], [ %13, %8 ]
%35 = phi i64 [ %12, %24 ], [ %23, %21 ], [ %12, %18 ], [ %12, %15 ], [ %12, %8 ]
%36 = phi i32 [ %11, %24 ], [ %11, %21 ], [ %11, %18 ], [ %11, %15 ], [ 1, %8 ]
%37 = phi i32 [ 1, %24 ], [ %10, %21 ], [ %10, %18 ], [ %10, %15 ], [ %10, %8 ]
%38 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%39 = icmp eq i8 %38, -1
br i1 %39, label %40, label %8
40: ; preds = %33, %2
%41 = phi i64 [ 0, %2 ], [ %34, %33 ]
%42 = phi i64 [ 10, %2 ], [ %35, %33 ]
%43 = phi i32 [ 0, %2 ], [ %36, %33 ]
%44 = phi i32 [ 0, %2 ], [ %37, %33 ]
%45 = icmp slt i32 %0, 5
br i1 %45, label %46, label %50
46: ; preds = %40
%47 = load i8*, i8** %1
%48 = call i32 @usage(i8* %47)
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %40
%51 = add i64 %41, -37
%52 = icmp ult i64 %51, -35
br i1 %52, label %53, label %58
53: ; preds = %50
%54 = load i8*, i8** %1
%55 = call i32 @usage(i8* %54)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %41)
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %50
%59 = add i64 %42, -37
%60 = icmp ult i64 %59, -36
br i1 %60, label %61, label %66
61: ; preds = %58
%62 = load i8*, i8** %1
%63 = call i32 @usage(i8* %62)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i64 %42)
%65 = call i32 @exit(i32 0)
unreachable
66: ; preds = %58
%67 = call i64 @myatoi(i64 %42, i8* %5)
%68 = icmp ne i32 %43, 0
%69 = sext i1 %68 to i64
%70 = xor i64 %67, %69
%71 = icmp eq i32 %44, 0
%72 = sub i64 0, %70
%73 = select i1 %71, i64 %70, i64 %72
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%75 = call i32 @memset(i8* %74, i32 0, i32 100)
%76 = call i32 @myitoa(i64 %41, i64 %73, i8* %74)
br label %77
77: ; preds = %77, %66
%78 = phi i8* [ %74, %66 ], [ %81, %77 ]
%79 = load i8, i8* %78
%80 = icmp eq i8 %79, 48
%81 = getelementptr inbounds i8, i8* %78, i64 1
br i1 %80, label %77, label %82
82: ; preds = %77
%83 = call i32 @puts(i8* %78)
ret i32 0
}