#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*/ free(char *);
int is_odd_digits(scalar_t__);
char *malloc(int);
int snprintf(char *, int, char *, int);
char *str_rev(char *, int);
scalar_t__ strtol(char *, char **, int);
bool is_reversible(int n) {
  int length = snprintf(NULL, 0, "%d", n);
  char *str = malloc(length + 1);
  snprintf(str, length + 1, "%d", n);
  str = str_rev(str, length);
  if (str[0] == '0') {
    free(str);
    return false;
  }
  char *ptr;
  bool result = is_odd_digits(n + strtol(str, &ptr, 10));
  free(str);
  return result;
}


x86 assembly (clang, -O0):
<is_reversible>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe85(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x8(%rbp),%ecx
lea    0xe5a(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <str_rev@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11e0 <is_reversible+0x80>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1218 <is_reversible+0xb8>
movslq -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
call   1080 <is_odd_digits@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_reversible>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r15d
lea    0xe8a(%rip),%r14
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1050 <snprintf@plt>
mov    %eax,%r12d
lea    0x1(%r12),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1050 <snprintf@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <str_rev@plt>
mov    %rax,%rbx
cmpb   $0x30,(%rax)
jne    11c6 <is_reversible+0x66>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    11f2 <is_reversible+0x92>
movslq %r15d,%rbp
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1060 <strtol@plt>
add    %rax,%rbp
mov    %rbp,%rdi
call   1080 <is_odd_digits@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @is_reversible(i32 %0) {
%2 = alloca i8*
%3 = tail call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = add nsw i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @snprintf(i8* %5, i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = tail call i8* @str_rev(i8* %5, i32 %3)
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 48
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @free(i8* %7)
br label %19
12: ; preds = %1
%13 = bitcast i8** %2 to i8*
%14 = sext i32 %0 to i64
%15 = call i64 @strtol(i8* %7, i8** %2, i32 10)
%16 = add nsw i64 %15, %14
%17 = tail call i32 @is_odd_digits(i64 %16)
%18 = tail call i32 @free(i8* %7)
br label %19
19: ; preds = %12, %10
%20 = phi i32 [ 0, %10 ], [ %17, %12 ]
ret i32 %20
}