#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 const *);
void string_reverse(char *dst, const char *src) {
  if (src == NULL) {
    return;
  }
  const char *src_start = src;
  char *dst_end = dst + strlen(src) - 1;
  while ((*dst_end-- = *src_start++)) {
    ;
  }
}


x86 assembly (clang, -O0):
<string_reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1130 <string_reverse+0x20>
jmp    118c <string_reverse+0x7c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     118c <string_reverse+0x7c>
jmp    115d <string_reverse+0x4d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_reverse>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1141 <string_reverse+0x31>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
cltq
add    %r14,%rax
add    $0xffffffffffffffff,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
mov    %cl,(%rax)
add    $0xffffffffffffffff,%rax
test   %cl,%cl
jne    1130 <string_reverse+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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