#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*/ assert(int /*<<< orphan*/);
int strlen(char *);
const char *reverse(char *str) {
  char *p = str;
  char *q;
  assert(str != NULL);
  q = str + strlen(str) - 1;
  while (p < q) {
    char ch = *p;
    *p++ = *q;
    *q-- = ch;
  }
  return str;
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
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
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11b2 <reverse+0x92>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    116b <reverse+0x4b>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %r14,%rax
add    $0xffffffffffffffff,%rax
cmp    %r14,%rax
jbe    116c <reverse+0x4c>
lea    0x1(%r14),%rcx
nop
movzbl -0x1(%rcx),%edx
movzbl (%rax),%ebx
mov    %bl,-0x1(%rcx)
mov    %dl,(%rax)
add    $0xffffffffffffffff,%rax
lea    0x1(%rcx),%rdx
cmp    %rax,%rcx
mov    %rdx,%rcx
jb     1150 <reverse+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @reverse(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** %3
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
store i8* %16, i8** %4
br label %17
17: ; preds = %21, %1
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = icmp ult i8* %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
store i8 %23, i8* %5
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
store i8 %25, i8* %26
%28 = load i8, i8* %5
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %4
store i8 %28, i8* %29
br label %17
31: ; preds = %17
%32 = load i8*, i8** %2
ret i8* %32
}

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