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


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%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    11cc <reverse+0xbc>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0xc(%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    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
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    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1131 <reverse+0x21>
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 i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %4
br label %5
5: ; preds = %41, %1
%6 = load i32, i32* %4
%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 %44
11: ; preds = %5
%12 = load i8*, i8** %2
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
store i32 %17, i32* %3
%18 = load i8*, i8** %2
%19 = load i8*, i8** %2
%20 = call i32 @strlen(i8* %19)
%21 = load i32, i32* %4
%22 = sub nsw i32 %20, %21
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %18, i64 %24
%26 = load i8, i8* %25
%27 = load i8*, i8** %2
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
%31 = load i32, i32* %3
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %2
%34 = load i8*, i8** %2
%35 = call i32 @strlen(i8* %34)
%36 = load i32, i32* %4
%37 = sub nsw i32 %35, %36
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %33, i64 %39
store i8 %32, i8* %40
br label %41
41: ; preds = %11
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %5
44: ; 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
}