#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 *);
int strlen(char *);
int main(void) {
  char string_1[20];
  char string_2[20];
  printf("You want to say:");
  scanf("%19s", string_1);
  for (int index = 0; index <= strlen(string_1); index++) {
    string_2[index] = string_1[strlen(string_1) - index - 1];
  }
  printf("\nI understood: %s\n", string_2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xeb9(%rip),%rdi
call   1050 <scanf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
cmp    %ecx,%eax
jg     11ab <main+0x7b>
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
sub    -0x44(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x20(%rbp,%rax,1),%cl
movslq -0x44(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1164 <main+0x34>
lea    -0x40(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec4(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
js     11aa <main+0x7a>
mov    $0xffffffff,%ebp
mov    $0xffffffffffffffff,%rbx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
cltq
movzbl (%rsp,%rax,1),%eax
mov    %al,0x21(%rsp,%rbx,1)
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    $0xffffffff,%ebp
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1180 <main+0x50>
lea    0xe65(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"You want to say:\00"
@.str.1 = [5 x i8] c"%19s\00"
@.str.2 = [19 x i8] c"\0AI understood: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %6)
store i32 0, i32* %4
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %4
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = icmp sle i32 %9, %11
br i1 %12, label %13, label %28
13: ; preds = %8
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = load i32, i32* %4
%17 = sub nsw i32 %15, %16
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %23
store i8 %21, i8* %24
br label %25
25: ; preds = %13
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %8
28: ; preds = %8
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"You want to say:\00"
@.str.1 = [5 x i8] c"%19s\00"
@.str.2 = [19 x i8] c"\0AI understood: %s\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32 @strlen(i8* %3)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %11, %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %4)
ret i32 0
11: ; preds = %0, %11
%12 = phi i64 [ %21, %11 ], [ 0, %0 ]
%13 = trunc i64 %12 to i32
%14 = call i32 @strlen(i8* %3)
%15 = xor i32 %13, -1
%16 = add i32 %14, %15
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %12
store i8 %19, i8* %20
%21 = add nuw nsw i64 %12, 1
%22 = call i32 @strlen(i8* %3)
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %12, %23
br i1 %24, label %11, label %9
}