#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 greatestPalindrome(unsigned int, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
void problem4(unsigned base, unsigned digits) {
  printf("Problem 4: The largest ");
  switch (base) {
  case 8:
    printf("octal ");
    break;
  case 10:
    printf("decimal ");
    break;
  case 16:
    printf("hexadecimal ");
    break;
  default:
    printf("base-%u ", base);
    break;
  }
  printf("palindrome made from the product of two %u-digit numbers is ",
         digits);
  switch (base) {
  case 8:
    printf("0%o", greatestPalindrome(base, digits));
    break;
  case 16:
    printf("0x%X", greatestPalindrome(base, digits));
    break;
  default:
    printf("%d", greatestPalindrome(base, digits));
    break;
  }
  printf(".\n");
}


x86 assembly (clang, -O0):
<problem4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x8,%eax
je     1172 <problem4+0x52>
jmp    1150 <problem4+0x30>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
je     1185 <problem4+0x65>
jmp    1161 <problem4+0x41>
mov    -0xc(%rbp),%eax
sub    $0x10,%eax
je     1198 <problem4+0x78>
jmp    11ab <problem4+0x8b>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bc <problem4+0x9c>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bc <problem4+0x9c>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bc <problem4+0x9c>
mov    -0x4(%rbp),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x8,%eax
je     11f2 <problem4+0xd2>
jmp    11e1 <problem4+0xc1>
mov    -0x10(%rbp),%eax
sub    $0x10,%eax
je     1212 <problem4+0xf2>
jmp    1232 <problem4+0x112>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <greatestPalindrome@plt>
mov    %eax,%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <problem4+0x12d>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <greatestPalindrome@plt>
mov    %eax,%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <problem4+0x12d>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <greatestPalindrome@plt>
mov    %eax,%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<problem4>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x10,%ebp
je     1172 <problem4+0x42>
cmp    $0xa,%ebp
je     118e <problem4+0x5e>
cmp    $0x8,%ebp
jne    119e <problem4+0x6e>
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf07(%rip),%rbx
mov    $0x8,%ebp
jmp    11b5 <problem4+0x85>
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeef(%rip),%rbx
mov    $0x10,%ebp
jmp    11b5 <problem4+0x85>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ae <problem4+0x7e>
lea    0xe87(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec6(%rip),%rbx
lea    0xe79(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <greatestPalindrome@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Problem 4: The largest \00"
@.str.1 = [7 x i8] c"octal \00"
@.str.2 = [9 x i8] c"decimal \00"
@.str.3 = [13 x i8] c"hexadecimal \00"
@.str.4 = [9 x i8] c"base-%u \00"
@.str.5 = [61 x i8] c"palindrome made from the product of two %u-digit numbers is \00"
@.str.6 = [4 x i8] c"0%o\00"
@.str.7 = [5 x i8] c"0x%X\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [3 x i8] c".\0A\00"
define void @problem4(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* %3
switch i32 %6, label %13 [
i32 8, label %7
i32 10, label %9
i32 16, label %11
]
7: ; preds = %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %16
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %16
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %16
13: ; preds = %2
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %11, %9, %7
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
switch i32 %19, label %30 [
i32 8, label %20
i32 16, label %25
]
20: ; preds = %16
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call i32 @greatestPalindrome(i32 %21, i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %23)
br label %35
25: ; preds = %16
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 @greatestPalindrome(i32 %26, i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %28)
br label %35
30: ; preds = %16
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = call i32 @greatestPalindrome(i32 %31, i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %30, %25, %20
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Problem 4: The largest \00"
@.str.1 = [7 x i8] c"octal \00"
@.str.2 = [9 x i8] c"decimal \00"
@.str.3 = [13 x i8] c"hexadecimal \00"
@.str.4 = [9 x i8] c"base-%u \00"
@.str.5 = [61 x i8] c"palindrome made from the product of two %u-digit numbers is \00"
@.str.6 = [4 x i8] c"0%o\00"
@.str.7 = [5 x i8] c"0x%X\00"
@.str.8 = [3 x i8] c"%d\00"
@str = [2 x i8] c".\00"
define void @problem4(i32 %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
switch i32 %0, label %10 [
i32 8, label %4
i32 10, label %6
i32 16, label %8
]
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %12
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %12
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %12
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %12
12: ; preds = %6, %10, %8, %4
%13 = phi i32 [ 16, %8 ], [ 8, %4 ], [ %0, %10 ], [ %0, %6 ]
%14 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), %8 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), %4 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), %10 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), %6 ]
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0), i32 %1)
%16 = tail call i32 @greatestPalindrome(i32 %13, i32 %1)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %14, i32 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}