#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 s[]) {
  int i, j;
  char tmp;
  int len = strlen(s);
  for (i = 0, j = len - 1; i < len / 2; i++, j--) {
    tmp = s[i];
    s[i] = s[j];
    s[j] = tmp;
  }
}


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,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    119f <reverse+0x8f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x11(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1138 <reverse+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     11aa <reverse+0x9a>
mov    %eax,%ecx
shr    %eax
cmp    $0x1,%eax
jne    1136 <reverse+0x26>
xor    %edx,%edx
test   $0x1,%al
jne    1198 <reverse+0x88>
jmp    11aa <reverse+0x9a>
mov    %rcx,%rsi
shr    %rsi
and    $0xfffffffe,%esi
neg    %rsi
mov    $0x1,%edx
nopw   0x0(%rax,%rax,1)
movzbl -0x1(%r14,%rdx,1),%edi
movzbl -0x1(%r14,%rcx,1),%ebx
mov    %bl,-0x1(%r14,%rdx,1)
mov    %dil,-0x1(%r14,%rcx,1)
movzbl (%r14,%rdx,1),%edi
movzbl -0x2(%r14,%rcx,1),%ebx
mov    %bl,(%r14,%rdx,1)
mov    %dil,-0x2(%r14,%rcx,1)
add    $0xfffffffffffffffe,%rcx
lea    (%rsi,%rdx,1),%rdi
add    $0x2,%rdi
add    $0x2,%rdx
cmp    $0x1,%rdi
jne    1150 <reverse+0x40>
add    $0xffffffffffffffff,%rdx
test   $0x1,%al
je     11aa <reverse+0x9a>
mov    (%r14,%rdx,1),%al
mov    -0x1(%rcx,%r14,1),%bl
mov    %bl,(%r14,%rdx,1)
mov    %al,-0x1(%rcx,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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