#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 */
typedef int /*<<< orphan*/ num_string;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int base = 0;
  int num = 9999;
  char num_string[15];
  int i = 15 - 2;
  memset(num_string, 32, sizeof(num_string));
  if (argc != 2) {
    printf("Usage: interesing-digits [BASE]\n");
    return -1;
  } else {
    base = atoi(argv[1]);
  }
  while (num >= base) {
    int tmp = num % base;
    if (tmp < 10) {
      num_string[i] = (char)(tmp + 48);
    } else {
      num_string[i] = (char)(tmp + 55);
    }
    num = num / base;
    i--;
  }
  num_string[i] = (char)((num % base) + 48);
  num_string[15 - 1] = '\0';
  printf("%s\n", num_string);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x270f,-0x18(%rbp)
movl   $0xd,-0x2c(%rbp)
lea    -0x27(%rbp),%rdi
mov    $0x20,%esi
mov    $0xf,%edx
call   1040 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     1192 <main+0x62>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1235 <main+0x105>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    11a7 <main+0x77>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1204 <main+0xd4>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x30(%rbp)
cmpl   $0xa,-0x30(%rbp)
jge    11dc <main+0xac>
mov    -0x30(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
movslq -0x2c(%rbp),%rax
mov    %cl,-0x27(%rbp,%rax,1)
jmp    11ec <main+0xbc>
mov    -0x30(%rbp),%eax
add    $0x37,%eax
mov    %al,%cl
movslq -0x2c(%rbp),%rax
mov    %cl,-0x27(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a7 <main+0x77>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x14(%rbp)
add    $0x30,%edx
mov    %dl,%cl
movslq -0x2c(%rbp),%rax
mov    %cl,-0x27(%rbp,%rax,1)
movb   $0x0,-0x19(%rbp)
lea    -0x27(%rbp),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x9(%rsp),%rdi
mov    $0x20,%esi
mov    $0xf,%edx
call   1040 <memset@plt>
cmp    $0x2,%ebp
jne    1172 <main+0x42>
mov    0x8(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
cmp    $0x270f,%eax
jle    1185 <main+0x55>
mov    $0xd,%esi
mov    $0x270f,%eax
jmp    11d4 <main+0xa4>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    11ef <main+0xbf>
lea    0x16(%rsp),%rdi
mov    $0x270f,%eax
movabs $0xd00000000,%rsi
mov    $0x30,%r8d
movabs $0xffffffff00000000,%rbx
ff ff ff
nopl   0x0(%rax)
cltd
idiv   %ecx
cmp    $0xa,%edx
mov    $0x37,%ebp
cmovl  %r8d,%ebp
add    %dl,%bpl
mov    %bpl,(%rdi)
add    $0xffffffffffffffff,%rdi
add    %rbx,%rsi
cmp    %ecx,%eax
jge    11b0 <main+0x80>
sar    $0x20,%rsi
cltd
idiv   %ecx
add    $0x30,%dl
mov    %dl,0x9(%rsp,%rsi,1)
movb   $0x0,0x17(%rsp)
lea    0x9(%rsp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Usage: interesing-digits [BASE]\0A\00"
@.str.1 = [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 i32
%7 = alloca i32
%8 = alloca [15 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 9999, i32* %7
store i32 13, i32* %9
%11 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 32, i32 15)
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %6
br label %22
22: ; preds = %17
br label %23
23: ; preds = %47, %22
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = icmp sge i32 %24, %25
br i1 %26, label %27, label %53
27: ; preds = %23
%28 = load i32, i32* %7
%29 = load i32, i32* %6
%30 = srem i32 %28, %29
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = icmp slt i32 %31, 10
br i1 %32, label %33, label %40
33: ; preds = %27
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 48
%36 = trunc i32 %35 to i8
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 %38
store i8 %36, i8* %39
br label %47
40: ; preds = %27
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 55
%43 = trunc i32 %42 to i8
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 %45
store i8 %43, i8* %46
br label %47
47: ; preds = %40, %33
%48 = load i32, i32* %7
%49 = load i32, i32* %6
%50 = sdiv i32 %48, %49
store i32 %50, i32* %7
%51 = load i32, i32* %9
%52 = add nsw i32 %51, -1
store i32 %52, i32* %9
br label %23
53: ; preds = %23
%54 = load i32, i32* %7
%55 = load i32, i32* %6
%56 = srem i32 %54, %55
%57 = add nsw i32 %56, 48
%58 = trunc i32 %57 to i8
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 %60
store i8 %58, i8* %61
%62 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 14
store i8 0, i8* %62
%63 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %63)
store i32 0, i32* %3
br label %65
65: ; preds = %53, %15
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@str = [32 x i8] c"Usage: interesing-digits [BASE]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [15 x i8]
%4 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 32, i32 15)
%6 = icmp eq i32 %0, 2
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %38
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @atoi(i8* %11)
%13 = icmp sgt i32 %12, 9999
br i1 %13, label %29, label %14
14: ; preds = %9, %14
%15 = phi i64 [ %24, %14 ], [ 13, %9 ]
%16 = phi i32 [ %23, %14 ], [ 9999, %9 ]
%17 = srem i32 %16, %12
%18 = icmp slt i32 %17, 10
%19 = trunc i32 %17 to i8
%20 = select i1 %18, i8 48, i8 55
%21 = add i8 %20, %19
%22 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 %15
store i8 %21, i8* %22
%23 = sdiv i32 %16, %12
%24 = add i64 %15, -1
%25 = icmp slt i32 %23, %12
br i1 %25, label %26, label %14
26: ; preds = %14
%27 = shl i64 %24, 32
%28 = ashr exact i64 %27, 32
br label %29
29: ; preds = %26, %9
%30 = phi i32 [ 9999, %9 ], [ %23, %26 ]
%31 = phi i64 [ 13, %9 ], [ %28, %26 ]
%32 = srem i32 %30, %12
%33 = trunc i32 %32 to i8
%34 = add i8 %33, 48
%35 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 %31
store i8 %34, i8* %35
%36 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 14
store i8 0, i8* %36
%37 = call i32 @puts(i8* %4)
br label %38
38: ; preds = %29, %7
%39 = phi i32 [ -1, %7 ], [ 0, %29 ]
ret i32 %39
}