#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*/ swap(char *, char *);
void reverse_inplace(char *str) {
  char *idx = str;
  while (*idx)
    idx++;
  int length = idx - str;
  for (int i = 0; i < length / 2; i++) {
    swap(&str[i], &str[length - 1 - i]);
  }
}


x86 assembly (clang, -O0):
<reverse_inplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1142 <reverse_inplace+0x32>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <reverse_inplace+0x14>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11a5 <reverse_inplace+0x95>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
sub    -0x18(%rbp),%eax
cltq
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1157 <reverse_inplace+0x47>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_inplace>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0xffffffffffffffff,%r12
movabs $0xfffffffe00000000,%rbx
ff ff ff
movabs $0x100000000,%rax
nopw   0x0(%rax,%rax,1)
add    %rax,%rbx
cmpb   $0x0,0x1(%r14,%r12,1)
lea    0x1(%r12),%r12
jne    1140 <reverse_inplace+0x30>
cmp    $0x2,%r12d
jl     118f <reverse_inplace+0x7f>
shr    %r12d
movabs $0xffffffff00000000,%r13
ff ff ff
mov    %r14,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rsi
sar    $0x20,%rsi
add    %r14,%rsi
mov    %r15,%rdi
call   1030 <swap@plt>
add    %r13,%rbx
add    $0x1,%r15
add    $0xffffffffffffffff,%r12
jne    1170 <reverse_inplace+0x60>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @reverse_inplace(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %6, %2 ]
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
%6 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %5, label %7, label %2
7: ; preds = %2
%8 = ptrtoint i8* %3 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = lshr i64 %10, 1
%15 = and i64 %14, 2147483647
br label %17
16: ; preds = %17, %7
ret void
17: ; preds = %13, %17
%18 = phi i64 [ 0, %13 ], [ %26, %17 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = xor i64 %18, -1
%21 = add i64 %10, %20
%22 = shl i64 %21, 32
%23 = ashr exact i64 %22, 32
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = tail call i32 @swap(i8* %19, i8* %24)
%26 = add nuw nsw i64 %18, 1
%27 = icmp eq i64 %26, %15
br i1 %27, label %16, label %17
}