#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 *);
char *malloc(size_t);
scalar_t__ strcmp(char *, char *);
size_t strlen(char *);
int is_palindrome(char *string) {
  int same_forward_and_backward = 0;
  size_t length = strlen(string);
  char *reverse = malloc(length + 1);
  size_t i = 0;
  while (string[i] != '\0') {
    reverse[length - 1 - i] = string[i];
    i++;
  }
  reverse[length] = '\0';
  if (0 == strcmp(string, reverse)) {
    same_forward_and_backward = 1;
  }
  free(reverse);
  return same_forward_and_backward;
}


x86 assembly (clang, -O0):
<is_palindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11bd <is_palindrome+0x7d>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
sub    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1179 <is_palindrome+0x39>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11eb <is_palindrome+0xab>
movl   $0x1,-0xc(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_palindrome>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    (%r14),%al
test   %al,%al
je     1191 <is_palindrome+0x51>
lea    0x1(%r14),%rcx
lea    (%r15,%rbx,1),%rdx
add    $0xffffffffffffffff,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %al,(%rdx)
movzbl (%rcx),%eax
add    $0x1,%rcx
add    $0xffffffffffffffff,%rdx
test   %al,%al
jne    1180 <is_palindrome+0x40>
movb   $0x0,(%rbx,%r15,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_palindrome(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %3
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = add i64 %9, 1
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %5
store i64 0, i64* %6
br label %12
12: ; preds = %19, %1
%13 = load i8*, i8** %2
%14 = load i64, i64* %6
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %12
%20 = load i8*, i8** %2
%21 = load i64, i64* %6
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %5
%25 = load i64, i64* %4
%26 = sub i64 %25, 1
%27 = load i64, i64* %6
%28 = sub i64 %26, %27
%29 = getelementptr inbounds i8, i8* %24, i64 %28
store i8 %23, i8* %29
%30 = load i64, i64* %6
%31 = add i64 %30, 1
store i64 %31, i64* %6
br label %12
32: ; preds = %12
%33 = load i8*, i8** %5
%34 = load i64, i64* %4
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %2
%37 = load i8*, i8** %5
%38 = call i64 @strcmp(i8* %36, i8* %37)
%39 = icmp eq i64 0, %38
br i1 %39, label %40, label %41
40: ; preds = %32
store i32 1, i32* %3
br label %41
41: ; preds = %40, %32
%42 = load i8*, i8** %5
%43 = call i32 @free(i8* %42)
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
define i32 @is_palindrome(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 1
%4 = tail call i8* @malloc(i64 %3)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %1, %7
%8 = phi i8 [ %15, %7 ], [ %5, %1 ]
%9 = phi i64 [ %13, %7 ], [ 0, %1 ]
%10 = xor i64 %9, -1
%11 = add i64 %2, %10
%12 = getelementptr inbounds i8, i8* %4, i64 %11
store i8 %8, i8* %12
%13 = add i64 %9, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %7, %1
%18 = getelementptr inbounds i8, i8* %4, i64 %2
store i8 0, i8* %18
%19 = tail call i64 @strcmp(i8* %0, i8* %4)
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
%22 = tail call i32 @free(i8* %4)
ret i32 %21
}