#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 *GetReverse(char *original) {
  char *sourceptr, *destinptr;
  int length;
  char *buffer;
  length = strlen(original);
  buffer = (char *)malloc(sizeof(char) * (length + 1));
  if (buffer == NULL) {
    return NULL;
  }
  sourceptr = original;
  destinptr = buffer + length;
  *destinptr = '\0';
  destinptr--;
  while (*sourceptr != '\0') {
    (*destinptr) = *sourceptr;
    destinptr--;
    sourceptr++;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<GetReverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1167 <GetReverse+0x47>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <GetReverse+0xb2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ca <GetReverse+0xaa>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1191 <GetReverse+0x71>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetReverse>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
lea    0x1(%r14),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1173 <GetReverse+0x53>
movslq %r14d,%rdx
movb   $0x0,(%rax,%rdx,1)
mov    (%rbx),%cl
test   %cl,%cl
je     1175 <GetReverse+0x55>
add    %rax,%rdx
add    $0xffffffffffffffff,%rdx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %cl,(%rdx)
movzbl (%rbx),%ecx
add    $0xffffffffffffffff,%rdx
add    $0x1,%rbx
test   %cl,%cl
jne    1160 <GetReverse+0x40>
jmp    1175 <GetReverse+0x55>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @GetReverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = mul i64 1, %12
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %1
store i8* null, i8** %2
br label %44
20: ; preds = %1
%21 = load i8*, i8** %3
store i8* %21, i8** %4
%22 = load i8*, i8** %7
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8* %25, i8** %5
%26 = load i8*, i8** %5
store i8 0, i8* %26
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %5
br label %29
29: ; preds = %34, %20
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = load i8*, i8** %5
store i8 %36, i8* %37
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 -1
store i8* %39, i8** %5
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %4
br label %29
42: ; preds = %29
%43 = load i8*, i8** %7
store i8* %43, i8** %2
br label %44
44: ; preds = %42, %19
%45 = load i8*, i8** %2
ret i8* %45
}

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