#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*/ generateNextPalindromeUtil(int *, int);
scalar_t__ ifAll9s(int *, int);
int /*<<< orphan*/ printArray(int *, int);
int /*<<< orphan*/ printf(char *);
void generateNextPalindrome(int num[], int n) {
  int i;
  printf("\nNext palindrome is:\n");
  if (ifAll9s(num, n)) {
    printf("1 ");
    for (i = 1; i < n; i++)
      printf("0 ");
    printf("1");
  } else {
    generateNextPalindromeUtil(num, n);
    printArray(num, n);
  }
}


x86 assembly (clang, -O0):
<generateNextPalindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <ifAll9s@plt>
cmp    $0x0,%rax
je     11bb <generateNextPalindrome+0x7b>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11aa <generateNextPalindrome+0x6a>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1184 <generateNextPalindrome+0x44>
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
jmp    11d3 <generateNextPalindrome+0x93>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <generateNextPalindromeUtil@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <printArray@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateNextPalindrome>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1080 <ifAll9s@plt>
test   %rax,%rax
je     11be <generateNextPalindrome+0x5e>
lea    0xe75(%rip),%rdi
call   1050 <printf@plt>
cmp    $0x2,%ebx
jl     11ad <generateNextPalindrome+0x4d>
add    $0xffffffff,%ebx
lea    0xe64(%rip),%r14
nop
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0xffffffff,%ebx
jne    11a0 <generateNextPalindrome+0x40>
mov    $0x31,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <generateNextPalindromeUtil@plt>
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <printArray@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"\0ANext palindrome is:\0A\00"
@.str.1 = [3 x i8] c"1 \00"
@.str.2 = [3 x i8] c"0 \00"
@.str.3 = [2 x i8] c"1\00"
define void @generateNextPalindrome(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = load i32*, i32** %3
%8 = load i32, i32* %4
%9 = call i64 @ifAll9s(i32* %7, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %5
br label %13
13: ; preds = %19, %11
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %13
22: ; preds = %13
%23 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %31
24: ; preds = %2
%25 = load i32*, i32** %3
%26 = load i32, i32* %4
%27 = call i32 @generateNextPalindromeUtil(i32* %25, i32 %26)
%28 = load i32*, i32** %3
%29 = load i32, i32* %4
%30 = call i32 @printArray(i32* %28, i32 %29)
br label %31
31: ; preds = %24, %22
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"1 \00"
@.str.2 = [3 x i8] c"0 \00"
@str = [21 x i8] c"\0ANext palindrome is:\00"
define void @generateNextPalindrome(i32* %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%4 = tail call i64 @ifAll9s(i32* %0, i32 %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp sgt i32 %1, 1
br i1 %8, label %9, label %14
9: ; preds = %6, %9
%10 = phi i32 [ %12, %9 ], [ 1, %6 ]
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = add nuw nsw i32 %10, 1
%13 = icmp eq i32 %12, %1
br i1 %13, label %14, label %9
14: ; preds = %9, %6
%15 = tail call i32 @putchar(i32 49)
br label %19
16: ; preds = %2
%17 = tail call i32 @generateNextPalindromeUtil(i32* %0, i32 %1)
%18 = tail call i32 @printArray(i32* %0, i32 %1)
br label %19
19: ; preds = %16, %14
ret void
}