#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 */
typedef size_t int32_t;

/* Variables and functions */
size_t strlen(char *);
void reverse(char *b) {
  int32_t i, j;
  char c;
  for (i = 0, j = strlen(b) - 1; i < j; i++, j--) {
    c = b[i];
    b[i] = b[j];
    b[j] = c;
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1192 <reverse+0x82>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x19(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1135 <reverse+0x25>
add    $0x20,%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 -0x1(%rbx,%rcx,1),%esi
movzbl (%rbx,%rax,1),%edx
mov    %dl,-0x1(%rbx,%rcx,1)
mov    %sil,(%rbx,%rax,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 i8
store i8* %0, i8** %2
store i64 0, i64* %3
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = sub i64 %7, 1
store i64 %8, i64* %4
br label %9
9: ; preds = %29, %1
%10 = load i64, i64* %3
%11 = load i64, i64* %4
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = load i64, i64* %3
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %5
%18 = load i8*, i8** %2
%19 = load i64, i64* %4
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = load i8*, i8** %2
%23 = load i64, i64* %3
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8 %21, i8* %24
%25 = load i8, i8* %5
%26 = load i8*, i8** %2
%27 = load i64, i64* %4
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8 %25, i8* %28
br label %29
29: ; preds = %13
%30 = load i64, i64* %3
%31 = add i64 %30, 1
store i64 %31, i64* %3
%32 = load i64, i64* %4
%33 = add i64 %32, -1
store i64 %33, i64* %4
br label %9
34: ; preds = %9
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 %7
%9 = load i8, i8* %8
%10 = getelementptr inbounds i8, i8* %0, i64 %6
%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
}