#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) {
  char *send = s + strlen(s) - 1;
  if (*send == '\n')
    --send;
  while (s < send) {
    char temp;
    temp = *s;
    *s++ = *send;
    *send-- = temp;
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    115d <reverse+0x4d>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1162 <reverse+0x52>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a9 <reverse+0x99>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1162 <reverse+0x52>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
xor    %ecx,%ecx
cmpb   $0xa,-0x1(%rbx,%rax,1)
lea    -0x1(%rbx,%rax,1),%rdx
sete   %cl
sub    %rcx,%rdx
cmp    %rbx,%rdx
jbe    115c <reverse+0x4c>
neg    %rcx
add    %rcx,%rax
add    %rbx,%rax
add    $0xfffffffffffffffe,%rax
nop
movzbl (%rbx),%ecx
movzbl 0x1(%rax),%edx
mov    %dl,(%rbx)
add    $0x1,%rbx
mov    %cl,0x1(%rax)
lea    -0x1(%rax),%rcx
cmp    %rax,%rbx
mov    %rcx,%rax
jb     1140 <reverse+0x30>
pop    %rbx
ret

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

LLVM IR (-O2):
define void @reverse(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 10
%8 = sext i1 %7 to i64
%9 = getelementptr i8, i8* %5, i64 %8
%10 = icmp ugt i8* %9, %0
br i1 %10, label %11, label %19
11: ; preds = %1, %11
%12 = phi i8* [ %16, %11 ], [ %0, %1 ]
%13 = phi i8* [ %17, %11 ], [ %9, %1 ]
%14 = load i8, i8* %12
%15 = load i8, i8* %13
%16 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %15, i8* %12
%17 = getelementptr inbounds i8, i8* %13, i64 -1
store i8 %14, i8* %13
%18 = icmp ult i8* %16, %17
br i1 %18, label %11, label %19
19: ; preds = %11, %1
ret void
}