#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 */
typedef char uint8_t;

/* Variables and functions */
void swizzle(void *start, size_t len) {
  void *end = (void *)((char *)start + len - 1);
  while (start < end) {
    uint8_t tmp = *((char *)start);
    *((char *)start) = *((char *)end);
    start = (void *)((char *)start + 1);
    *((char *)end) = tmp;
    end = (void *)((char *)end - 1);
  }
}


x86 assembly (clang, -O0):
<swizzle>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1165 <swizzle+0x65>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    111c <swizzle+0x1c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<swizzle>:
lea    (%rdi,%rsi,1),%rax
add    $0xffffffffffffffff,%rax
cmp    %rdi,%rax
jbe    113c <swizzle+0x3c>
add    $0x1,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rdi),%ecx
movzbl (%rax),%edx
mov    %dl,-0x1(%rdi)
mov    %cl,(%rax)
add    $0xffffffffffffffff,%rax
lea    0x1(%rdi),%rcx
cmp    %rax,%rdi
mov    %rcx,%rdi
jb     1120 <swizzle+0x20>
ret

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

LLVM IR (-O2):
define void @swizzle(i8* %0, i64 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 %1
%4 = getelementptr inbounds i8, i8* %3, i64 -1
%5 = icmp ugt i8* %4, %0
br i1 %5, label %6, label %14
6: ; preds = %2, %6
%7 = phi i8* [ %12, %6 ], [ %4, %2 ]
%8 = phi i8* [ %11, %6 ], [ %0, %2 ]
%9 = load i8, i8* %8
%10 = load i8, i8* %7
store i8 %10, i8* %8
%11 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %9, i8* %7
%12 = getelementptr inbounds i8, i8* %7, i64 -1
%13 = icmp ult i8* %11, %12
br i1 %13, label %6, label %14
14: ; preds = %6, %2
ret void
}