#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*/ isPalindrome(char *, int);
int /*<<< orphan*/ printf(char *, char, ...);
int makePalindrome(char *str, int len, int pad) {
  if (!isPalindrome(str + pad, len - pad))
    return 0;
  printf("%d\n%s", pad, str);
  for (int i = pad - 1; i >= 0; i--)
    printf("%c", str[i]);
  return 1;
}


x86 assembly (clang, -O0):
<makePalindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
call   1040 <isPalindrome@plt>
cmp    $0x0,%eax
jne    115d <makePalindrome+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <makePalindrome+0x97>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rdx
lea    0xe95(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11b0 <makePalindrome+0x90>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe6f(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    117e <makePalindrome+0x5e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makePalindrome>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
movslq %edx,%rax
add    %rax,%rdi
sub    %eax,%esi
call   1040 <isPalindrome@plt>
test   %eax,%eax
je     118d <makePalindrome+0x6d>
movsbl %bpl,%esi
lea    0xeb8(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%r14d
test   %ebp,%ebp
jle    1190 <makePalindrome+0x70>
mov    %ebp,%ebp
add    $0x1,%rbp
lea    0xe9d(%rip),%r15
nopl   0x0(%rax)
lea    -0x2(%rbp),%eax
movsbl (%rbx,%rax,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
ja     1170 <makePalindrome+0x50>
jmp    1190 <makePalindrome+0x70>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d\0A%s\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @makePalindrome(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = sub nsw i32 %13, %14
%16 = call i32 @isPalindrome(i8* %12, i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %3
store i32 0, i32* %4
br label %40
19: ; preds = %3
%20 = load i32, i32* %7
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %5
%23 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %21, i8* %22)
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %8
br label %26
26: ; preds = %36, %19
%27 = load i32, i32* %8
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i8*, i8** %5
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %8
%38 = add nsw i32 %37, -1
store i32 %38, i32* %8
br label %26
39: ; preds = %26
store i32 1, i32* %4
br label %40
40: ; preds = %39, %18
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d\0A%s\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @makePalindrome(i8* %0, i32 %1, i32 %2) {
%4 = sext i32 %2 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = sub nsw i32 %1, %2
%7 = tail call i32 @isPalindrome(i8* %5, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %3
%10 = trunc i32 %2 to i8
%11 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %10, i8* %0)
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %23
13: ; preds = %9
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ %14, %13 ], [ %17, %15 ]
%17 = add nsw i64 %16, -1
%18 = and i64 %17, 4294967295
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %20)
%22 = icmp ugt i64 %16, 1
br i1 %22, label %15, label %23
23: ; preds = %15, %9, %3
%24 = phi i32 [ 0, %3 ], [ 1, %9 ], [ 1, %15 ]
ret i32 %24
}