#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 */
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char *userInput;
  int length = 0;
  int ctr;
  int error = 0;
  userInput = malloc(sizeof(char *));
  printf("Enter a word or string:");
  scanf("%[^\n]s", userInput);
  while (*(userInput + length) != '\0')
    length++;
  for (ctr = 0; ctr < length; ctr++) {
    if (*(userInput + ctr) != *(userInput + length - 1 - ctr)) {
      error = 1;
      break;
    }
  }
  if (error == 1)
    printf("%s is not a palindrome", userInput);
  else
    printf("%s is a palindrome", userInput);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xea4(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119c <main+0x6c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <main+0x49>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fb <main+0xcb>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
add    %rdx,%rcx
movslq -0x18(%rbp),%rsi
xor    %edx,%edx
sub    %rsi,%rdx
movsbl -0x1(%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11e8 <main+0xb8>
movl   $0x1,-0x1c(%rbp)
jmp    11fb <main+0xcb>
jmp    11ed <main+0xbd>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a3 <main+0x73>
cmpl   $0x1,-0x1c(%rbp)
jne    121c <main+0xec>
mov    -0x10(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122e <main+0xfe>
mov    -0x10(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xeb8(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
cmpb   $0x0,(%r14,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1160 <main+0x30>
lea    0xec4(%rip),%rdi
cmp    $0x1,%ebx
je     11ab <main+0x7b>
add    $0xffffffff,%ebx
lea    (%r14,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
xor    %ecx,%ecx
lea    0xe94(%rip),%rsi
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rcx,1),%edx
cmp    (%rax),%dl
jne    11a8 <main+0x78>
add    $0x1,%rcx
add    $0xffffffffffffffff,%rax
cmp    %rcx,%rbx
jne    1190 <main+0x60>
jmp    11ab <main+0x7b>
mov    %rsi,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter a word or string:\00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [23 x i8] c"%s is not a palindrome\00"
@.str.3 = [19 x i8] c"%s is a palindrome\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %5
%6 = call i8* @malloc(i32 8)
store i8* %6, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %2
%9 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %18, %0
%11 = load i8*, i8** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %10
21: ; preds = %10
store i32 0, i32* %4
br label %22
22: ; preds = %47, %21
%23 = load i32, i32* %4
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %50
26: ; preds = %22
%27 = load i8*, i8** %2
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = load i8*, i8** %2
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = getelementptr inbounds i8, i8* %36, i64 -1
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = sub i64 0, %39
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %32, %43
br i1 %44, label %45, label %46
45: ; preds = %26
store i32 1, i32* %5
br label %50
46: ; preds = %26
br label %47
47: ; preds = %46
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %22
50: ; preds = %45, %22
%51 = load i32, i32* %5
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i8*, i8** %2
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %54)
br label %59
56: ; preds = %50
%57 = load i8*, i8** %2
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %56, %53
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter a word or string:\00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [23 x i8] c"%s is not a palindrome\00"
@.str.3 = [19 x i8] c"%s is a palindrome\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %4
4: ; preds = %4, %0
%5 = phi i64 [ %9, %4 ], [ 0, %0 ]
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = add nuw i64 %5, 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = trunc i64 %5 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %28, label %13
13: ; preds = %10
%14 = and i64 %5, 4294967295
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
br label %19
17: ; preds = %19
%18 = icmp eq i64 %27, %14
br i1 %18, label %28, label %19
19: ; preds = %13, %17
%20 = phi i64 [ 0, %13 ], [ %27, %17 ]
%21 = getelementptr inbounds i8, i8* %1, i64 %20
%22 = load i8, i8* %21
%23 = sub nsw i64 0, %20
%24 = getelementptr inbounds i8, i8* %16, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %22, %25
%27 = add nuw nsw i64 %20, 1
br i1 %26, label %17, label %28
28: ; preds = %17, %19, %10
%29 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), %10 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %19 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), %17 ]
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %29, i8* %1)
ret i32 0
}