#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*/ print(char const *, int);
size_t strlen(char const *);
const char *revert(const char *str) {
  char *rev;
  size_t size = strlen(str);
  int i;
  str += size;
  for (i = 0; i < size; i++) {
    char ch = *(str--);
    print((const char *)&ch, 1);
    rev[i] = ch;
  }
  rev[size] = '\0';
  return (const char *)rev;
}


x86 assembly (clang, -O0):
<revert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1198 <revert+0x78>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
lea    -0x1d(%rbp),%rdi
mov    $0x1,%esi
call   1040 <print@plt>
mov    -0x1d(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <revert+0x2c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<revert>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    (%rbx,%rax,1),%al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
call   1040 <print@plt>

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

LLVM IR (-O2):
define noalias i8* @revert(i8* nocapture %0) {
%2 = alloca i8
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp ne i64 %3, 0
tail call void @llvm.assume(i1 %4)
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = load i8, i8* %5
store i8 %6, i8* %2
%7 = call i32 @print(i8* %2, i32 1)
unreachable
}