#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 *);
void reverse(char *cp) {
  int i;
  for (i = 0; i < strlen(cp) / 2; i++) {
    char ch = cp[i];
    cp[i] = cp[strlen(cp) - 1 - i];
    cp[strlen(cp) - 1 - i] = ch;
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11bd <reverse+0xad>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xd(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x21(%rbp),%dl
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <reverse+0x13>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     117a <reverse+0x6a>
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
cltq
movzbl (%r14,%rax,1),%eax
mov    %al,(%r14,%rbx,1)
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
cltq
mov    %r15b,(%r14,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
add    $0xffffffff,%ebp
cmp    %rax,%rbx
jl     1130 <reverse+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @reverse(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 1
br i1 %3, label %4, label %24
4: ; preds = %1, %4
%5 = phi i64 [ %19, %4 ], [ 0, %1 ]
%6 = trunc i64 %5 to i32
%7 = getelementptr inbounds i8, i8* %0, i64 %5
%8 = load i8, i8* %7
%9 = tail call i32 @strlen(i8* %0)
%10 = xor i32 %6, -1
%11 = add i32 %9, %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
store i8 %14, i8* %7
%15 = tail call i32 @strlen(i8* %0)
%16 = add i32 %15, %10
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 %8, i8* %18
%19 = add nuw nsw i64 %5, 1
%20 = tail call i32 @strlen(i8* %0)
%21 = sdiv i32 %20, 2
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %19, %22
br i1 %23, label %4, label %24
24: ; preds = %4, %1
ret void
}