#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 lenght(char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char str[20] = "lolz xd xd xd";
  char *p = str;
  int leng = lenght(p);
  int k = leng;
  for (int i = 0; i <= leng / 2; i++) {
    char temp = str[i];
    str[i] = str[k - 1];
    str[k - 1] = temp;
    k--;
  }
  printf("Reversed: %s\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec5(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <lenght@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jg     11d2 <main+0xb2>
movslq -0x34(%rbp),%rax
mov    -0x20(%rbp,%rax,1),%al
mov    %al,-0x35(%rbp)
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x20(%rbp,%rax,1),%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x35(%rbp),%cl
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116f <main+0x4f>
lea    -0x20(%rbp),%rsi
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <lenght@plt>
cmp    $0xffffffff,%eax
jl     11d2 <main+0xb2>
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
movslq %eax,%rdx
add    $0x1,%edi
add    $0x1,%eax
cmp    $0x3,%eax
jae    116f <main+0x4f>
xor    %eax,%eax
test   $0x1,%dil
jne    11c2 <main+0xa2>
jmp    11d2 <main+0xb2>
mov    %edi,%esi
and    $0xfffffffe,%esi
neg    %rsi
mov    $0x1,%eax
nopl   0x0(%rax)
movzbl -0x1(%rsp,%rax,1),%ebx
movzbl -0x1(%rsp,%rdx,1),%ecx
mov    %cl,-0x1(%rsp,%rax,1)
mov    %bl,-0x1(%rsp,%rdx,1)
movzbl (%rsp,%rax,1),%ecx
movzbl -0x2(%rsp,%rdx,1),%ebx
mov    %bl,(%rsp,%rax,1)
mov    %cl,-0x2(%rsp,%rdx,1)
add    $0xfffffffffffffffe,%rdx
lea    (%rsi,%rax,1),%rcx
add    $0x2,%rcx
add    $0x2,%rax
cmp    $0x1,%rcx
jne    1180 <main+0x60>
add    $0xffffffffffffffff,%rax
test   $0x1,%dil
je     11d2 <main+0xb2>
mov    (%rsp,%rax,1),%cl
mov    -0x1(%rdx,%r14,1),%bl
mov    %bl,(%rsp,%rax,1)
mov    %cl,-0x1(%rdx,%r14,1)
lea    0xe3b(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@__const.main.str = [20 x i8] c"lolz xd xd xd\00\00\00\00\00\00\00"
@.str = [14 x i8] c"Reversed: %s\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = call i32 @lenght(i8* %2)
%4 = icmp slt i32 %3, -1
br i1 %4, label %25, label %5
5: ; preds = %0
%6 = sdiv i32 %3, 2
%7 = sext i32 %3 to i64
%8 = add nuw nsw i32 %6, 1
%9 = zext i32 %8 to i64
%10 = and i64 %9, 1
%11 = add i32 %3, 1
%12 = icmp ult i32 %11, 3
br i1 %12, label %15, label %13
13: ; preds = %5
%14 = and i64 %9, 4294967294
br label %27
15: ; preds = %27, %5
%16 = phi i64 [ 0, %5 ], [ %42, %27 ]
%17 = phi i64 [ %7, %5 ], [ %39, %27 ]
%18 = icmp eq i64 %10, 0
br i1 %18, label %25, label %19
19: ; preds = %15
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %16
%21 = load i8, i8* %20
%22 = add nsw i64 %17, -1
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
store i8 %24, i8* %20
store i8 %21, i8* %23
br label %25
25: ; preds = %19, %15, %0
%26 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %2)
ret i32 0
27: ; preds = %27, %13
%28 = phi i64 [ 0, %13 ], [ %42, %27 ]
%29 = phi i64 [ %7, %13 ], [ %39, %27 ]
%30 = phi i64 [ 0, %13 ], [ %43, %27 ]
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %28
%32 = load i8, i8* %31
%33 = add nsw i64 %29, -1
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %33
%35 = load i8, i8* %34
store i8 %35, i8* %31
store i8 %32, i8* %34
%36 = or i64 %28, 1
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = add nsw i64 %29, -2
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %39
%41 = load i8, i8* %40
store i8 %41, i8* %37
store i8 %38, i8* %40
%42 = add nuw nsw i64 %28, 2
%43 = add i64 %30, 2
%44 = icmp eq i64 %43, %14
br i1 %44, label %15, label %27
}