#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 *);
char *reverse_string_in_place(char *str) {
  char *i, *f;
  char ch;
  int len = strlen(str);
  if (len == 0)
    return str;
  i = str;
  f = &str[len - 1];
  while (i < f) {
    ch = *i;
    *i = *f;
    *f = ch;
    i++;
    f--;
  }
  return str;
}


x86 assembly (clang, -O0):
<reverse_string_in_place>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    113f <reverse_string_in_place+0x2f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ac <reverse_string_in_place+0x9c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11a4 <reverse_string_in_place+0x94>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    115b <reverse_string_in_place+0x4b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_string_in_place>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     114c <reverse_string_in_place+0x3c>
add    $0xffffffff,%eax
add    %r14,%rax
add    $0xffffffffffffffff,%rax
mov    %r14,%rcx
xchg   %ax,%ax
movzbl (%rcx),%edx
movzbl 0x1(%rax),%ebx
mov    %bl,(%rcx)
mov    %dl,0x1(%rax)
add    $0x1,%rcx
lea    -0x1(%rax),%rdx
cmp    %rax,%rcx
mov    %rdx,%rax
jb     1130 <reverse_string_in_place+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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