#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 *);
int /*<<< orphan*/ swap(char *, char *);
void reverse(char *str) {
  int x = strlen(str);
  for (int y = 0; y < x / 2; y++) {
    swap(&str[y], &str[x - y - 1]);
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    118d <reverse+0x6d>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
sub    $0x1,%eax
cltq
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113f <reverse+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     116c <reverse+0x4c>
mov    %eax,%ebx
mov    %eax,%r12d
shr    %r12d
add    $0xffffffff,%ebx
mov    %r14,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %ebx,%rbx
lea    (%r14,%rbx,1),%rsi
mov    %r15,%rdi
call   1040 <swap@plt>
add    $0xffffffff,%ebx
add    $0x1,%r15
add    $0xffffffffffffffff,%r12
jne    1150 <reverse+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %25, %1
%8 = load i32, i32* %4
%9 = load i32, i32* %3
%10 = sdiv i32 %9, 2
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %28
12: ; preds = %7
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = sub nsw i32 %18, %19
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %17, i64 %22
%24 = call i32 @swap(i8* %16, i8* %23)
br label %25
25: ; preds = %12
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %7
28: ; preds = %7
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 %7
4: ; preds = %1
%5 = lshr i32 %2, 1
%6 = zext i32 %5 to i64
br label %8
7: ; preds = %8, %1
ret void
8: ; preds = %4, %8
%9 = phi i64 [ 0, %4 ], [ %17, %8 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = trunc i64 %9 to i32
%12 = xor i32 %11, -1
%13 = add i32 %2, %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i32 @swap(i8* %10, i8* %15)
%17 = add nuw nsw i64 %9, 1
%18 = icmp eq i64 %17, %6
br i1 %18, label %7, label %8
}