#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 bswap_16(int);
scalar_t__ bswap_32(int);
scalar_t__ bswap_64(int);
int /*<<< orphan*/ printf(char *, unsigned long long, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long long, ...);
scalar_t__ strcmp(char *, char *);
int main() {
  char buf[100];
  printf("%x %x\n", bswap_16(0x1234), bswap_16(0x5678));
  snprintf(buf, 100, "%x %x", bswap_16(0x1234), bswap_16(0x5678));
  assert(strcmp(buf, "3412 7856") == 0);
  printf("%x\n", (unsigned int)bswap_32(0x12345678));
  snprintf(buf, 100, "%x", (unsigned int)bswap_32(0x12345678));
  assert(strcmp(buf, "78563412") == 0);
  printf("%llx\n", (unsigned long long)bswap_64(0x123456789ABCDEFull));
  snprintf(buf, 100, "%llx",
           (unsigned long long)bswap_64(0x123456789ABCDEFull));
  assert(strcmp(buf, "efcdab8967452301") == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1234,%edi
call   1090 <bswap_16@plt>
cltq
mov    %rax,-0x98(%rbp)
mov    $0x5678,%edi
call   1090 <bswap_16@plt>
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    $0x1234,%edi
call   1090 <bswap_16@plt>
cltq
mov    %rax,-0x88(%rbp)
mov    $0x5678,%edi
call   1090 <bswap_16@plt>
mov    -0x90(%rbp),%rdi
mov    -0x88(%rbp),%rcx
mov    %eax,%r8d
mov    $0x64,%esi
lea    0xe0c(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x12345678,%edi
call   1070 <bswap_32@plt>
mov    %eax,%eax
mov    %eax,%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    $0x12345678,%edi
call   1070 <bswap_32@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%eax
mov    %eax,%ecx
mov    $0x64,%esi
lea    0xda5(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x89abcdef,%edi
call   1080 <bswap_64@plt>
mov    %rax,%rsi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x89abcdef,%edi
call   1080 <bswap_64@plt>
mov    -0x78(%rbp),%rdi
mov    %rax,%rcx
mov    $0x64,%esi
lea    0xd59(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xd4c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    $0x1234,%edi
call   1090 <bswap_16@plt>
movslq %eax,%rbx
mov    $0x5678,%edi
call   1090 <bswap_16@plt>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1234,%edi
call   1090 <bswap_16@plt>
movslq %eax,%rbx
mov    $0x5678,%edi
call   1090 <bswap_16@plt>
lea    0xe48(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x64,%esi
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe2f(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    $0x12345678,%edi
call   1070 <bswap_32@plt>
mov    %eax,%esi
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x12345678,%edi
call   1070 <bswap_32@plt>
mov    %eax,%ecx
lea    0xde9(%rip),%rdx
mov    %r14,%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xde0(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    $0x89abcdef,%edi
call   1080 <bswap_64@plt>
lea    0xdc2(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x89abcdef,%edi
call   1080 <bswap_64@plt>
lea    0xdad(%rip),%rdx
mov    %r14,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xd99(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%x %x\0A\00"
@.str.1 = [6 x i8] c"%x %x\00"
@.str.2 = [10 x i8] c"3412 7856\00"
@.str.3 = [4 x i8] c"%x\0A\00"
@.str.4 = [3 x i8] c"%x\00"
@.str.5 = [9 x i8] c"78563412\00"
@.str.6 = [6 x i8] c"%llx\0A\00"
@.str.7 = [5 x i8] c"%llx\00"
@.str.8 = [17 x i8] c"efcdab8967452301\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
store i32 0, i32* %1
%3 = call i32 @bswap_16(i32 4660)
%4 = sext i32 %3 to i64
%5 = call i32 @bswap_16(i32 22136)
%6 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %4, i32 %5)
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = call i32 @bswap_16(i32 4660)
%9 = sext i32 %8 to i64
%10 = call i32 @bswap_16(i32 22136)
%11 = call i32 (i8*, i32, i8*, i64, ...) @snprintf(i8* %7, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %9, i32 %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i64 @bswap_32(i32 305419896)
%18 = trunc i64 %17 to i32
%19 = zext i32 %18 to i64
%20 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%22 = call i64 @bswap_32(i32 305419896)
%23 = trunc i64 %22 to i32
%24 = zext i32 %23 to i64
%25 = call i32 (i8*, i32, i8*, i64, ...) @snprintf(i8* %21, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 %24)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i64 @bswap_64(i32 -1985229329)
%32 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i64 %31)
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%34 = call i64 @bswap_64(i32 -1985229329)
%35 = call i32 (i8*, i32, i8*, i64, ...) @snprintf(i8* %33, i32 100, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i64 %34)
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%x %x\0A\00"
@.str.1 = [6 x i8] c"%x %x\00"
@.str.2 = [10 x i8] c"3412 7856\00"
@.str.3 = [4 x i8] c"%x\0A\00"
@.str.4 = [3 x i8] c"%x\00"
@.str.5 = [9 x i8] c"78563412\00"
@.str.6 = [6 x i8] c"%llx\0A\00"
@.str.7 = [5 x i8] c"%llx\00"
@.str.8 = [17 x i8] c"efcdab8967452301\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @bswap_16(i32 4660)
%4 = sext i32 %3 to i64
%5 = tail call i32 @bswap_16(i32 22136)
%6 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %4, i32 %5)
%7 = tail call i32 @bswap_16(i32 4660)
%8 = sext i32 %7 to i64
%9 = tail call i32 @bswap_16(i32 22136)
%10 = call i32 (i8*, i32, i8*, i64, ...) @snprintf(i8* %2, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %8, i32 %9)
%11 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = call i64 @bswap_32(i32 305419896)
%16 = and i64 %15, 4294967295
%17 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %16)
%18 = call i64 @bswap_32(i32 305419896)
%19 = and i64 %18, 4294967295
%20 = call i32 (i8*, i32, i8*, i64, ...) @snprintf(i8* %2, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 %19)
%21 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i64 @bswap_64(i32 -1985229329)
%26 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i64 %25)
%27 = call i64 @bswap_64(i32 -1985229329)
%28 = call i32 (i8*, i32, i8*, i64, ...) @snprintf(i8* %2, i32 100, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i64 %27)
%29 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
ret i32 0
}