#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 *);
void main() {
  char str[12], temp;
  int len, i;
  printf("Enter a string:\n");
  gets(str);
  len = strlen(str);
  printf("the str length is:%d\n", len);
  for (i = 0; i < len / 2; i++) {
    temp = str[i];
    str[i] = str[len - 1 - i];
    str[len - 1 - i] = temp;
  }
  printf("%s", str);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1050 <gets@plt>
lea    -0xc(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11d3 <main+0xa3>
movslq -0x18(%rbp),%rax
mov    -0xc(%rbp,%rax,1),%al
mov    %al,-0xd(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
sub    -0x18(%rbp),%eax
cltq
mov    -0xc(%rbp,%rax,1),%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0xd(%rbp),%cl
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
sub    -0x18(%rbp),%eax
cltq
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1173 <main+0x43>
lea    -0xc(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <gets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%r14d
jl     11f9 <main+0xb9>
mov    %r14d,%r8d
shr    %r8d
cmp    $0x1,%r8d
jne    1191 <main+0x51>
xor    %ecx,%ecx
jmp    11d9 <main+0x99>
mov    %r8d,%edx
and    $0xfffffffe,%edx
lea    -0x2(%r14),%esi
xor    %ecx,%ecx
nopl   (%rax)
movzbl 0xc(%rsp,%rcx,1),%eax
lea    0x1(%rsi),%edi
movslq %edi,%rdi
movzbl 0xc(%rsp,%rdi,1),%ebx
mov    %bl,0xc(%rsp,%rcx,1)
mov    %al,0xc(%rsp,%rdi,1)
movzbl 0xd(%rsp,%rcx,1),%eax
movslq %esi,%rsi
movzbl 0xc(%rsp,%rsi,1),%ebx
mov    %bl,0xd(%rsp,%rcx,1)
mov    %al,0xc(%rsp,%rsi,1)
add    $0x2,%rcx
add    $0xfffffffe,%esi
cmp    %rcx,%rdx
jne    11a0 <main+0x60>
test   $0x1,%r8b
je     11f9 <main+0xb9>
mov    0xc(%rsp,%rcx,1),%al
mov    %ecx,%edx
not    %edx
add    %edx,%r14d
movslq %r14d,%rdx
mov    0xc(%rsp,%rdx,1),%bl
mov    %bl,0xc(%rsp,%rcx,1)
mov    %al,0xc(%rsp,%rdx,1)
lea    0xe16(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a string:\0A\00"
@.str.1 = [22 x i8] c"the str length is:%d\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @main() {
%1 = alloca [12 x i8]
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %10)
store i32 0, i32* %4
br label %12
12: ; preds = %39, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = sdiv i32 %14, 2
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %42
17: ; preds = %12
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %2
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, 1
%24 = load i32, i32* %4
%25 = sub nsw i32 %23, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %30
store i8 %28, i8* %31
%32 = load i8, i8* %2
%33 = load i32, i32* %3
%34 = sub nsw i32 %33, 1
%35 = load i32, i32* %4
%36 = sub nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %37
store i8 %32, i8* %38
br label %39
39: ; preds = %17
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %12
42: ; preds = %12
%43 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %43)
ret void
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"the str length is:%d\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@str = [16 x i8] c"Enter a string:\00"
define void @main() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = call i32 @strlen(i8* %2)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp sgt i32 %5, 1
br i1 %7, label %8, label %50
8: ; preds = %0
%9 = lshr i32 %5, 1
%10 = zext i32 %9 to i64
%11 = and i64 %10, 1
%12 = icmp eq i32 %9, 1
br i1 %12, label %38, label %13
13: ; preds = %8
%14 = and i64 %10, 2147483646
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 0, %13 ], [ %35, %15 ]
%17 = phi i64 [ 0, %13 ], [ %36, %15 ]
%18 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %16
%19 = load i8, i8* %18
%20 = trunc i64 %16 to i32
%21 = xor i32 %20, -1
%22 = add i32 %5, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %23
%25 = load i8, i8* %24
store i8 %25, i8* %18
store i8 %19, i8* %24
%26 = or i64 %16, 1
%27 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = trunc i64 %26 to i32
%30 = xor i32 %29, -1
%31 = add i32 %5, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %32
%34 = load i8, i8* %33
store i8 %34, i8* %27
store i8 %28, i8* %33
%35 = add nuw nsw i64 %16, 2
%36 = add i64 %17, 2
%37 = icmp eq i64 %36, %14
br i1 %37, label %38, label %15
38: ; preds = %15, %8
%39 = phi i64 [ 0, %8 ], [ %35, %15 ]
%40 = icmp eq i64 %11, 0
br i1 %40, label %50, label %41
41: ; preds = %38
%42 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %39
%43 = load i8, i8* %42
%44 = trunc i64 %39 to i32
%45 = xor i32 %44, -1
%46 = add i32 %5, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %47
%49 = load i8, i8* %48
store i8 %49, i8* %42
store i8 %43, i8* %48
br label %50
50: ; preds = %41, %38, %0
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret void
}