#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char **);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main() {
  char str[100], tmp, rev[100];
  int begin, end;
  printf("Enter string: ");
  scanf("%s", &str);
  strcpy(rev, str);
  begin = 0;
  end = strlen(str) - 1;
  while (begin < end) {
    tmp = str[begin];
    str[begin] = str[end];
    str[end] = tmp;
    begin++;
    end--;
  }
  printf("Reverse string: %s\n", str);
  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>
lea    -0x70(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1070 <scanf@plt>
lea    -0xe0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0xe4(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xe8(%rbp)
mov    -0xe4(%rbp),%eax
cmp    -0xe8(%rbp),%eax
jge    1213 <main+0xc3>
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    11ac <main+0x5c>
lea    -0x70(%rbp),%rsi
lea    0xdf4(%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    1256 <main+0x106>
lea    -0x70(%rbp),%rsi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1268 <main+0x118>
lea    -0x70(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xe0,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea2(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0x70(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     11c0 <main+0x70>
mov    %eax,%eax
add    $0xfffffffffffffffe,%rax
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%rsp,%rcx,1),%edx
movzbl 0x1(%rsp,%rax,1),%ebx
mov    %bl,(%rsp,%rcx,1)
mov    %dl,0x1(%rsp,%rax,1)
add    $0x1,%rcx
lea    -0x1(%rax),%rdx
cmp    %rax,%rcx
mov    %rdx,%rax
jl     11a0 <main+0x50>
lea    0xe4b(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x70(%rsp),%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xe3b(%rip),%rax
lea    0xe47(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter string: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [20 x i8] c"Reverse string: %s\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
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = bitcast [100 x i8]* %2 to i8**
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %8)
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%12 = call i32 @strcpy(i8* %10, i8* %11)
store i32 0, i32* %5
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %6
br label %16
16: ; preds = %20, %0
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
store i8 %24, i8* %3
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %30
store i8 %28, i8* %31
%32 = load i8, i8* %3
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %34
store i8 %32, i8* %35
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
%38 = load i32, i32* %6
%39 = add nsw i32 %38, -1
store i32 %39, i32* %6
br label %16
40: ; preds = %16
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%45 = call i64 @strcmp(i8* %43, i8* %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %48)
br label %53
50: ; preds = %40
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %47
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter string: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [20 x i8] c"Reverse string: %s\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 [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))
%6 = bitcast [100 x i8]* %1 to i8**
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %6)
%8 = call i32 @strcpy(i8* %4, i8* %3)
%9 = call i32 @strlen(i8* %3)
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %24
11: ; preds = %0
%12 = zext i32 %9 to i64
%13 = add nsw i64 %12, -1
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %21, %14 ]
%16 = phi i64 [ %13, %11 ], [ %22, %14 ]
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %15
%18 = load i8, i8* %17
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %16
%20 = load i8, i8* %19
store i8 %20, i8* %17
store i8 %18, i8* %19
%21 = add nuw nsw i64 %15, 1
%22 = add nsw i64 %16, -1
%23 = icmp slt i64 %21, %22
br i1 %23, label %14, label %24
24: ; preds = %14, %0
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%26 = call i64 @strcmp(i8* %4, i8* %3)
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, 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)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %28, i8* %3)
ret i32 0
}