#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 */
size_t strlen(char *);
void reverse(char *word) {
  size_t len = strlen(word), i, j;
  char c;
  i = 0;
  j = len - 1;
  while (i < j) {
    c = word[j];
    word[j] = word[i];
    word[i] = c;
    ++i;
    --j;
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    119a <reverse+0x8a>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x21(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    113d <reverse+0x2d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
add    $0xffffffffffffffff,%rax
je     1151 <reverse+0x41>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx,%rax,1),%esi
movzbl -0x1(%rbx,%rcx,1),%edx
mov    %dl,(%rbx,%rax,1)
mov    %sil,-0x1(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
lea    0x1(%rcx),%rdx
cmp    %rax,%rcx
mov    %rdx,%rcx
jb     1130 <reverse+0x20>
pop    %rbx
ret

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

LLVM IR (-O2):
define void @reverse(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, -1
%4 = icmp eq i64 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %13, %5 ], [ %3, %1 ]
%7 = phi i64 [ %12, %5 ], [ 0, %1 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %6
%9 = load i8, i8* %8
%10 = getelementptr inbounds i8, i8* %0, i64 %7
%11 = load i8, i8* %10
store i8 %11, i8* %8
store i8 %9, i8* %10
%12 = add nuw i64 %7, 1
%13 = add i64 %6, -1
%14 = icmp ult i64 %12, %13
br i1 %14, label %5, label %15
15: ; preds = %5, %1
ret void
}