#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 */
scalar_t__ malloc(int);
int strlen(char *);
char *reverseACString(char *s) {
  int i = 0;
  char *x = (char *)(malloc(strlen(s)) + 1);
  for (i = 0; i <= strlen(s); i++)
    x[i] = s[strlen(s) - i];
  return x;
}


x86 assembly (clang, -O0):
<reverseACString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1040 <malloc@plt>
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jg     11a7 <reverseACString+0x87>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <reverseACString+0x32>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseACString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
add    $0x1,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
js     118b <reverseACString+0x6b>
mov    $0xffffffffffffffff,%rbx
mov    %r15,%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
movzbl (%r12,%rax,1),%eax
mov    %al,0x1(%r14,%rbx,1)
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
add    $0x1,%rbx
add    $0xffffffffffffffff,%r12
cmp    %rax,%rbx
jl     1160 <reverseACString+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @reverseACString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = call i64 @malloc(i32 %6)
%8 = add nsw i64 %7, 1
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
store i32 0, i32* %3
br label %10
10: ; preds = %28, %1
%11 = load i32, i32* %3
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = icmp sle i32 %11, %13
br i1 %14, label %15, label %31
15: ; preds = %10
%16 = load i8*, i8** %2
%17 = load i8*, i8** %2
%18 = call i32 @strlen(i8* %17)
%19 = load i32, i32* %3
%20 = sub nsw i32 %18, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %16, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %4
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
br label %28
28: ; preds = %15
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %10
31: ; preds = %10
%32 = load i8*, i8** %4
ret i8* %32
}

LLVM IR (-O2):
define i8* @reverseACString(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @malloc(i32 %2)
%4 = add nsw i64 %3, 1
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %17, %8 ], [ 0, %1 ]
%10 = tail call i32 @strlen(i8* %0)
%11 = trunc i64 %9 to i32
%12 = sub nsw i32 %10, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 %15, i8* %16
%17 = add nuw nsw i64 %9, 1
%18 = tail call i32 @strlen(i8* %0)
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %9, %19
br i1 %20, label %8, label %21
21: ; preds = %8, %1
ret i8* %5
}