#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*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, char *);
size_t strlen(char *);
int main() {
  char *s = "hello";
  size_t l = strlen(s);
  char *r = (char *)malloc((l + 1) * sizeof(char));
  r[l] = '\0';
  int i;
  for (i = 0; i < l; i++) {
    r[i] = s[l - 1 - i];
  }
  printf("normal: %s\n", s);
  printf("reverse: %s\n", r);
  free(r);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11cc <main+0x8c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movslq -0x24(%rbp),%rdx
sub    %rdx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118f <main+0x4f>
mov    -0x10(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe2b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0x656c6c6f,(%rax)
movw   $0x68,0x4(%rax)
lea    0xeb5(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"hello\00"
@.str.1 = [12 x i8] c"normal: %s\0A\00"
@.str.2 = [13 x i8] c"reverse: %s\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i64 6)
%2 = inttoptr i64 %1 to i8*
%3 = getelementptr inbounds i8, i8* %2, i64 5
store i8 0, i8* %3
store i8 111, i8* %2
%4 = getelementptr inbounds i8, i8* %2, i64 1
store i8 108, i8* %4
%5 = getelementptr inbounds i8, i8* %2, i64 2
store i8 108, i8* %5
%6 = getelementptr inbounds i8, i8* %2, i64 3
store i8 101, i8* %6
%7 = getelementptr inbounds i8, i8* %2, i64 4
store i8 104, i8* %7
%8 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%10 = tail call i32 @free(i8* %2)
ret i32 0
}