#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 bs32(int);
int bs64(int);
int fail_real(int /*<<< orphan*/, int);
int test_bswap(void) {
  if (bs32(0xaa) != 0xaa000000)
    return fail_real(0, 51);
  if (bs32(0x1234) != 0x34120000)
    return fail_real(0, 53);
  if (bs64(0xaa) != 0xaa00000000000000UL)
    return fail_real(0, 55);
  if (bs64(0x1234567890abcdefUL) != 0xefcdab9078563412UL)
    return fail_real(0, 57);
  return 0x8;
}


x86 assembly (clang, -O0):
<test_bswap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xaa,%edi
call   1040 <bs32@plt>
cmp    $0xaa000000,%eax
je     1161 <test_bswap+0x31>
xor    %edi,%edi
mov    $0x33,%esi
call   1030 <fail_real@plt>
mov    %eax,-0x4(%rbp)
jmp    11f7 <test_bswap+0xc7>
mov    $0x1234,%edi
call   1040 <bs32@plt>
cmp    $0x34120000,%eax
je     118a <test_bswap+0x5a>
xor    %edi,%edi
mov    $0x35,%esi
call   1030 <fail_real@plt>
mov    %eax,-0x4(%rbp)
jmp    11f7 <test_bswap+0xc7>
mov    $0xaa,%edi
call   1050 <bs64@plt>
cltq
movabs $0xaa00000000000000,%rcx
cmp    %rcx,%rax
je     11bd <test_bswap+0x8d>
xor    %edi,%edi
mov    $0x37,%esi
call   1030 <fail_real@plt>
mov    %eax,-0x4(%rbp)
jmp    11f7 <test_bswap+0xc7>
mov    $0x90abcdef,%edi
call   1050 <bs64@plt>
cltq
movabs $0xefcdab9078563412,%rcx
ab cd ef
cmp    %rcx,%rax
je     11f0 <test_bswap+0xc0>
xor    %edi,%edi
mov    $0x39,%esi
call   1030 <fail_real@plt>
mov    %eax,-0x4(%rbp)
jmp    11f7 <test_bswap+0xc7>
movl   $0x8,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_bswap>:
push   %rax
mov    $0xaa,%edi
call   1040 <bs32@plt>
mov    $0x33,%esi
cmp    $0xaa000000,%eax
jne    116c <test_bswap+0x3c>
mov    $0x1234,%edi
call   1040 <bs32@plt>
mov    $0x35,%esi
cmp    $0x34120000,%eax
jne    116c <test_bswap+0x3c>
mov    $0xaa,%edi
call   1050 <bs64@plt>
mov    $0x37,%esi
xor    %edi,%edi
pop    %rax
jmp    1030 <fail_real@plt>

LLVM IR (-O0):
define i32 @test_bswap() {
%1 = alloca i32
%2 = call i32 @bs32(i32 170)
%3 = icmp ne i32 %2, -1442840576
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @fail_real(i32 0, i32 51)
store i32 %5, i32* %1
br label %24
6: ; preds = %0
%7 = call i32 @bs32(i32 4660)
%8 = icmp ne i32 %7, 873594880
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @fail_real(i32 0, i32 53)
store i32 %10, i32* %1
br label %24
11: ; preds = %6
%12 = call i32 @bs64(i32 170)
%13 = sext i32 %12 to i64
%14 = icmp ne i64 %13, -6196953087261802496
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @fail_real(i32 0, i32 55)
store i32 %16, i32* %1
br label %24
17: ; preds = %11
%18 = call i32 @bs64(i32 -1867788817)
%19 = sext i32 %18 to i64
%20 = icmp ne i64 %19, -1167088091436534766
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @fail_real(i32 0, i32 57)
store i32 %22, i32* %1
br label %24
23: ; preds = %17
store i32 8, i32* %1
br label %24
24: ; preds = %23, %21, %15, %9, %4
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
define i32 @test_bswap() {
%1 = tail call i32 @bs32(i32 170)
%2 = icmp eq i32 %1, -1442840576
br i1 %2, label %3, label %8
3: ; preds = %0
%4 = tail call i32 @bs32(i32 4660)
%5 = icmp eq i32 %4, 873594880
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @bs64(i32 170)
br label %8
8: ; preds = %3, %0, %6
%9 = phi i32 [ 55, %6 ], [ 51, %0 ], [ 53, %3 ]
%10 = tail call i32 @fail_real(i32 0, i32 %9)
ret i32 %10
}