#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main() {
  char str[10];
  char *start, *end, t;
  int len;
  printf("Enter string: ");
  gets(str);
  printf("Original string: %s\n", str);
  len = strlen(str);
  start = str;
  end = &str[len - 1];
  while (start < end) {
    t = *start;
    *start = *end;
    *end = t;
    start++;
    end--;
  }
  printf("Inversed string: %s\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe(%rbp),%rdi
call   1050 <gets@plt>
lea    -0xe(%rbp),%rsi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
lea    -0xe(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    -0xe(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11d9 <main+0xa9>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1190 <main+0x60>
lea    -0xe(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <gets@plt>
lea    0xeb8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     119c <main+0x6c>
add    $0xffffffff,%eax
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%ecx
movzbl 0x1(%rax),%edx
mov    %dl,(%rbx)
mov    %cl,0x1(%rax)
add    $0x1,%rbx
lea    -0x1(%rax),%rcx
cmp    %rax,%rbx
mov    %rcx,%rax
jb     1180 <main+0x50>
lea    0xe81(%rip),%rdi
lea    0x6(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter string: \00"
@.str.1 = [21 x i8] c"Original string: %s\0A\00"
@.str.2 = [21 x i8] c"Inversed string: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%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 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%9 = call i32 @gets(i8* %8)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %6
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
store i8* %14, i8** %3
%15 = load i32, i32* %6
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %17
store i8* %18, i8** %4
br label %19
19: ; preds = %23, %0
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = icmp ult i8* %20, %21
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
store i8 %25, i8* %5
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = load i8*, i8** %3
store i8 %27, i8* %28
%29 = load i8, i8* %5
%30 = load i8*, i8** %4
store i8 %29, i8* %30
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %3
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i32 -1
store i8* %34, i8** %4
br label %19
35: ; preds = %19
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter string: \00"
@.str.1 = [21 x i8] c"Original string: %s\0A\00"
@.str.2 = [21 x i8] c"Inversed string: %s\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = call i32 @strlen(i8* %2)
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %20
8: ; preds = %0
%9 = add nsw i32 %6, -1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %10
br label %12
12: ; preds = %8, %12
%13 = phi i8* [ %17, %12 ], [ %2, %8 ]
%14 = phi i8* [ %18, %12 ], [ %11, %8 ]
%15 = load i8, i8* %13
%16 = load i8, i8* %14
store i8 %16, i8* %13
store i8 %15, i8* %14
%17 = getelementptr inbounds i8, i8* %13, i64 1
%18 = getelementptr inbounds i8, i8* %14, i64 -1
%19 = icmp ult i8* %17, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %0
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret i32 0
}