#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 /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
void reverseprint(char *someChars) {
  char *someChars2 = (char *)malloc(sizeof(char) * strlen(someChars));
  int i = 0;
  for (i = 0; i < strlen(someChars); i++) {
    *(someChars2 + strlen(someChars) - 1 - i) = someChars[i];
  }
  *(someChars2 + strlen(someChars)) = '\0';
  printf("The copied string is %s\n", someChars2);
}


x86 assembly (clang, -O0):
<reverseprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11c9 <reverseprint+0x99>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x21(%rbp),%dl
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rsi
xor    %ecx,%ecx
sub    %rsi,%rcx
mov    %dl,-0x1(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <reverseprint+0x34>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rsi
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseprint>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    118a <reverseprint+0x5a>
mov    %r14,%r12
add    $0xffffffffffffffff,%r12
xor    %ebx,%ebx
nop
movzbl (%r15,%rbx,1),%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
mov    %bpl,(%r12,%rax,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
add    $0xffffffffffffffff,%r12
cmp    %rax,%rbx
jl     1160 <reverseprint+0x30>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,(%r14,%rax,1)
lea    0xe60(%rip),%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str = [25 x i8] c"The copied string is %s\0A\00"
define void @reverseprint(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %4, i64 -1
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %18, %9 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @strlen(i8* %0)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %8, i64 %14
%16 = sub nsw i64 0, %10
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8 %12, i8* %17
%18 = add nuw nsw i64 %10, 1
%19 = tail call i32 @strlen(i8* %0)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %9, label %22
22: ; preds = %9, %1
%23 = tail call i32 @strlen(i8* %0)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %4, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %4)
ret void
}