#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  char str[100], tmp, rev[100];
  int i, j, len;
  printf("Enter string: ");
  len = 0;
  do {
    tmp = getchar();
    str[len] = tmp;
    len++;
  } while (tmp != '\n');
  len--;
  str[len] = '\0';
  strcpy(rev, str);
  i = 0;
  j = len - 1;
  while (i < j) {
    tmp = str[i];
    str[i] = str[j];
    str[j] = tmp;
    i++;
    j--;
  }
  printf("Reverse string:\n");
  for (i = 0; i < len; i++) {
    putchar(str[i]);
  }
  printf("\n");
  if (strcmp(rev, str) == 0)
    printf("%s is palindrome!\n", str);
  else
    printf("%s is not palindrome!\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xec(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%cl
movslq -0xec(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0xec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xec(%rbp)
movsbl -0x71(%rbp),%eax
cmp    $0xa,%eax
jne    117a <main+0x2a>
mov    -0xec(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xec(%rbp)
movslq -0xec(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0xe0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0xe4(%rbp)
mov    -0xec(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xe8(%rbp)
mov    -0xe4(%rbp),%eax
cmp    -0xe8(%rbp),%eax
jge    1259 <main+0x109>
movslq -0xe4(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x71(%rbp)
movslq -0xe8(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%cl
movslq -0xe4(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x71(%rbp),%cl
movslq -0xe8(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
mov    -0xe8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xe8(%rbp)
jmp    11f2 <main+0xa2>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xe4(%rbp)
mov    -0xe4(%rbp),%eax
cmp    -0xec(%rbp),%eax
jge    12a8 <main+0x158>
movslq -0xe4(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    1271 <main+0x121>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xe0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12e7 <main+0x197>
lea    -0x70(%rbp),%rsi
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f9 <main+0x1a9>
lea    -0x70(%rbp),%rsi
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffffffffffff,%r14
movabs $0xfffffffe00000000,%rbx
ff ff ff
movabs $0x100000000,%r15
cs nopw 0x0(%rax,%rax,1)
nop
add    %r15,%rbx
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %al,0x1(%rsp,%r14,1)
add    $0x1,%r14
cmp    $0xa,%al
jne    11a0 <main+0x40>
mov    %r14d,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0x70(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <strcpy@plt>
cmp    $0x2,%r14d
jb     1200 <main+0xa0>
sar    $0x20,%rbx
add    $0xffffffffffffffff,%rbx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%rax,1),%ecx
movzbl 0x1(%rsp,%rbx,1),%edx
mov    %dl,(%rsp,%rax,1)
mov    %cl,0x1(%rsp,%rbx,1)
add    $0x1,%rax
lea    -0x1(%rbx),%rcx
cmp    %rbx,%rax
mov    %rcx,%rbx
jl     11e0 <main+0x80>
lea    0xe32(%rip),%rdi
call   1050 <puts@plt>
test   %r14d,%r14d
je     1232 <main+0xd2>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl (%rsp,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1220 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x70(%rsp),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
lea    0xdb9(%rip),%rax
lea    0xdc5(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter string: \00"
@.str.1 = [17 x i8] c"Reverse string:\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [19 x i8] c"%s is palindrome!\0A\00"
@.str.4 = [23 x i8] c"%s is not palindrome!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca [100 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %9
9: ; preds = %17, %0
%10 = call signext i8 (...) @getchar()
store i8 %10, i8* %3
%11 = load i8, i8* %3
%12 = load i32, i32* %7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %13
store i8 %11, i8* %14
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
br label %17
17: ; preds = %9
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br i1 %20, label %9, label %21
21: ; preds = %17
%22 = load i32, i32* %7
%23 = add nsw i32 %22, -1
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%29 = call i32 @strcpy(i8* %27, i8* %28)
store i32 0, i32* %5
%30 = load i32, i32* %7
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %6
br label %32
32: ; preds = %36, %21
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %56
36: ; preds = %32
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %38
%40 = load i8, i8* %39
store i8 %40, i8* %3
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %46
store i8 %44, i8* %47
%48 = load i8, i8* %3
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %50
store i8 %48, i8* %51
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
%54 = load i32, i32* %6
%55 = add nsw i32 %54, -1
store i32 %55, i32* %6
br label %32
56: ; preds = %32
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %58
58: ; preds = %68, %56
%59 = load i32, i32* %5
%60 = load i32, i32* %7
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %71
62: ; preds = %58
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %64
%66 = load i8, i8* %65
%67 = call i32 @putchar(i8 signext %66)
br label %68
68: ; preds = %62
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
br label %58
71: ; preds = %58
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%73 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%75 = call i64 @strcmp(i8* %73, i8* %74)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %71
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %78)
br label %83
80: ; preds = %71
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %80, %77
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter string: \00"
@.str.3 = [19 x i8] c"%s is palindrome!\0A\00"
@.str.4 = [23 x i8] c"%s is not palindrome!\0A\00"
@str = [16 x i8] c"Reverse string:\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %6, %0
%7 = phi i64 [ %10, %6 ], [ 0, %0 ]
%8 = tail call signext i8 (...) @getchar()
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %7
store i8 %8, i8* %9
%10 = add nuw i64 %7, 1
%11 = icmp eq i8 %8, 10
br i1 %11, label %12, label %6
12: ; preds = %6
%13 = trunc i64 %7 to i32
%14 = and i64 %7, 4294967295
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 @strcpy(i8* %4, i8* %3)
%17 = icmp ugt i32 %13, 1
br i1 %17, label %18, label %32
18: ; preds = %12
%19 = shl i64 %7, 32
%20 = add i64 %19, -4294967296
%21 = ashr exact i64 %20, 32
br label %22
22: ; preds = %18, %22
%23 = phi i64 [ 0, %18 ], [ %29, %22 ]
%24 = phi i64 [ %21, %18 ], [ %30, %22 ]
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %23
%26 = load i8, i8* %25
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %24
%28 = load i8, i8* %27
store i8 %28, i8* %25
store i8 %26, i8* %27
%29 = add nuw nsw i64 %23, 1
%30 = add nsw i64 %24, -1
%31 = icmp slt i64 %29, %30
br i1 %31, label %22, label %32
32: ; preds = %22, %12
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%34 = icmp eq i32 %13, 0
br i1 %34, label %42, label %35
35: ; preds = %32, %35
%36 = phi i64 [ %40, %35 ], [ 0, %32 ]
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = call i32 @putchar(i8 signext %38)
%40 = add nuw nsw i64 %36, 1
%41 = icmp eq i64 %40, %14
br i1 %41, label %42, label %35
42: ; preds = %35, %32
%43 = call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
%44 = call i64 @strcmp(i8* %4, i8* %3)
%45 = icmp eq i64 %44, 0
%46 = select i1 %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %46, i8* %3)
ret i32 0
}