#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 */
void *swap_bytes(void *s, size_t len) {
  for (char *b = s, *e = b + len - 1; b < e; b++, e--) {
    char t = *b;
    *b = *e;
    *e = t;
  }
  return s;
}


x86 assembly (clang, -O0):
<swap_bytes>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    116d <swap_bytes+0x6d>
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    1124 <swap_bytes+0x24>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_bytes>:
mov    %rdi,%rax
lea    (%rdi,%rsi,1),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rdi,%rcx
jbe    113d <swap_bytes+0x3d>
lea    0x1(%rax),%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%rdi),%esi
movzbl (%rcx),%edx
mov    %dl,-0x1(%rdi)
mov    %sil,(%rcx)
add    $0xffffffffffffffff,%rcx
lea    0x1(%rdi),%rdx
cmp    %rcx,%rdi
mov    %rdx,%rdi
jb     1120 <swap_bytes+0x20>
ret

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

LLVM IR (-O2):
define i8* @swap_bytes(i8* returned %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 %7, label %6
6: ; preds = %7, %2
ret i8* %0
7: ; preds = %2, %7
%8 = phi i8* [ %13, %7 ], [ %4, %2 ]
%9 = phi i8* [ %12, %7 ], [ %0, %2 ]
%10 = load i8, i8* %9
%11 = load i8, i8* %8
store i8 %11, i8* %9
store i8 %10, i8* %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = getelementptr inbounds i8, i8* %8, i64 -1
%14 = icmp ult i8* %12, %13
br i1 %14, label %7, label %6
}