#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 strlen(char *);
char *strrev(char *str) {
  char t, *i = str, *j = str + strlen(str);
  while (i < j) {
    t = *i;
    *(i++) = *(--j);
    *j = t;
  }
  return str;
}


x86 assembly (clang, -O0):
<strrev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    118d <strrev+0x7d>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
mov    -0x1(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x9(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
jmp    1145 <strrev+0x35>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrev>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    114e <strrev+0x3e>
mov    %eax,%eax
add    %r14,%rax
lea    0x1(%r14),%rcx
nopl   0x0(%rax)
movzbl -0x1(%rcx),%edx
movzbl -0x1(%rax),%ebx
mov    %bl,-0x1(%rcx)
mov    %dl,-0x1(%rax)
add    $0xffffffffffffffff,%rax
lea    0x1(%rcx),%rdx
cmp    %rax,%rcx
mov    %rdx,%rcx
jb     1130 <strrev+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @strrev(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = zext i32 %2 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %4, %7
%8 = phi i8* [ %11, %7 ], [ %6, %4 ]
%9 = phi i8* [ %13, %7 ], [ %0, %4 ]
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %8, i64 -1
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %12, i8* %9
store i8 %10, i8* %11
%14 = icmp ult i8* %13, %11
br i1 %14, label %7, label %15
15: ; preds = %7, %1
ret i8* %0
}