#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ swab(char *, char *, int /*<<< orphan*/);
int main(void) {
  char buf[] = "01234567";
  char buf2[] = "0123456";
  swab(buf, buf, strlen(buf));
  printf("test_swab: After swapping, buf=%s\n", buf);
  assert(strcmp(buf, "10325476") == 0);
  swab(buf2, buf2, strlen(buf2));
  printf("test_swab: After swapping, buf2=%s\n", buf2);
  assert(strcmp(buf2, "1032546") == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0xd(%rbp)
mov    0xe98(%rip),%al
mov    %al,-0x5(%rbp)
mov    0xe8f(%rip),%rax
mov    %rax,-0x15(%rbp)
lea    -0xd(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0xd(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0xd(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <swab@plt>
lea    -0xd(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
lea    -0xd(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0x15(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x15(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x15(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <swab@plt>
lea    -0x15(%rbp),%rsi
lea    0xe33(%rip),%rdi
call   1050 <printf@plt>
lea    -0x15(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movabs $0x3736353433323130,%rax
35 36 37
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
movabs $0x36353433323130,%rax
mov    %rax,0x18(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <swab@plt>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <swab@plt>
lea    0xe56(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.buf = [9 x i8] c"01234567\00"
@__const.main.buf2 = [8 x i8] c"0123456\00"
@.str = [35 x i8] c"test_swab: After swapping, buf=%s\0A\00"
@.str.1 = [9 x i8] c"10325476\00"
@.str.2 = [36 x i8] c"test_swab: After swapping, buf2=%s\0A\00"
@.str.3 = [8 x i8] c"1032546\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i8]
%3 = alloca [8 x i8]
store i32 0, i32* %1
%4 = bitcast [9 x i8]* %2 to i8*
%5 = bitcast [8 x i8]* %3 to i8*
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
%10 = call i32 @swab(i8* %6, i8* %7, i32 %9)
%11 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%12 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @swab(i8* %18, i8* %19, i32 %21)
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf = [9 x i8] c"01234567\00"
@.str = [35 x i8] c"test_swab: After swapping, buf=%s\0A\00"
@.str.1 = [9 x i8] c"10325476\00"
@.str.2 = [36 x i8] c"test_swab: After swapping, buf2=%s\0A\00"
@.str.3 = [8 x i8] c"1032546\00"
define i32 @main() {
%1 = alloca [9 x i8]
%2 = alloca i64
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%4 = bitcast i64* %2 to i8*
store i64 15258147055874352, i64* %2
%5 = call i32 @strlen(i8* %3)
%6 = call i32 @swab(i8* %3, i8* %3, i32 %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %3)
%8 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = call i32 @strlen(i8* %4)
%13 = call i32 @swab(i8* %4, i8* %4, i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%15 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
ret i32 0
}