#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 *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
size_t strlen(char *);
char *Reverse(char *str) {
  if (strlen(str) == 1) {
    return strdup(str);
  } else {
    char buf[20];
    char *rstr;
    memset(buf, 0, 20);
    rstr = Reverse(str + 1);
    strcpy(buf, rstr);
    buf[strlen(buf)] = *str;
    buf[strlen(buf)] = 0;
    free(rstr);
    return strdup(buf);
  }
}


x86 assembly (clang, -O0):
<Reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%rax
jne    1191 <Reverse+0x31>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11fc <Reverse+0x9c>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1070 <Reverse@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x39(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x39(%rbp),%cl
mov    %cl,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
lea    -0x30(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Reverse>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
call   1050 <strlen@plt>
cmp    $0x1,%rax
jne    1188 <Reverse+0x28>
mov    %rbx,%rdi
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <strdup@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
lea    0x1(%rbx),%rdi
call   1070 <Reverse@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    (%rbx),%bl
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %bl,(%rsp,%rax,1)
mov    %r14,%rdi
call   1050 <strlen@plt>
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1080 <strdup@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @Reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [20 x i8]
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = icmp eq i64 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %2
br label %33
12: ; preds = %1
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 20)
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i8* @Reverse(i8* %16)
store i8* %17, i8** %5
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%19 = load i8*, i8** %5
%20 = call i32 @strcpy(i8* %18, i8* %19)
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %24
store i8 %22, i8* %25
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%27 = call i64 @strlen(i8* %26)
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %27
store i8 0, i8* %28
%29 = load i8*, i8** %5
%30 = call i32 @free(i8* %29)
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%32 = call i8* @strdup(i8* %31)
store i8* %32, i8** %2
br label %33
33: ; preds = %12, %9
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
define noalias i8* @Reverse(i8* nocapture %0) {
%2 = alloca [20 x i8]
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp eq i64 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i8* @strdup(i8* %0)
br label %20
7: ; preds = %1
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 20)
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = call i8* @Reverse(i8* %10)
%12 = call i32 @strcpy(i8* %8, i8* %11)
%13 = load i8, i8* %0
%14 = call i64 @strlen(i8* %8)
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %14
store i8 %13, i8* %15
%16 = call i64 @strlen(i8* %8)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @free(i8* %11)
%19 = call i8* @strdup(i8* %8)
br label %20
20: ; preds = %7, %5
%21 = phi i8* [ %6, %5 ], [ %19, %7 ]
ret i8* %21
}