#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 strrev(char *buff) {
  char ch;
  int low = 0;
  int high = 0;
  int len = 0;
  len = strlen(buff);
  high = len;
  while (high > low) {
    ch = buff[low];
    buff[low] = buff[high];
    buff[high] = ch;
    low++;
    high--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<strrev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1198 <strrev+0x88>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <strrev+0x33>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrev>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1151 <strrev+0x41>
mov    %eax,%eax
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    %rcx,%rax
mov    %rdx,%rcx
jg     1130 <strrev+0x20>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @strrev(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ %5, %4 ], [ %14, %6 ]
%8 = phi i64 [ 0, %4 ], [ %13, %6 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %0, i64 %7
%12 = load i8, i8* %11
store i8 %12, i8* %9
store i8 %10, i8* %11
%13 = add nuw nsw i64 %8, 1
%14 = add nsw i64 %7, -1
%15 = icmp sgt i64 %14, %13
br i1 %15, label %6, label %16
16: ; preds = %6, %1
ret i32 0
}