#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ Dswap2BArr(void *, int);
int /*<<< orphan*/ Dswap4BArr(void *, int);
int /*<<< orphan*/ Dswap8BArr(void *, int);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
int fread_sw(void *data, int size, int nb, FILE *f, int swap) {
  fread(data, size, nb, f);
  if (swap) {
    switch (size) {
    case 8:
      Dswap8BArr(data, nb);
      break;
    case 4:
      Dswap4BArr(data, nb);
      break;
    case 2:
      Dswap2BArr(data, nb);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<fread_sw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1030 <fread@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11e0 <fread_sw+0xa0>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x2,%eax
je     11cf <fread_sw+0x8f>
jmp    118b <fread_sw+0x4b>
mov    -0x20(%rbp),%eax
sub    $0x4,%eax
je     11be <fread_sw+0x7e>
jmp    119c <fread_sw+0x5c>
mov    -0x20(%rbp),%eax
sub    $0x8,%eax
jne    11db <fread_sw+0x9b>
jmp    11ad <fread_sw+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <Dswap8BArr@plt>
jmp    11db <fread_sw+0x9b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1050 <Dswap4BArr@plt>
jmp    11db <fread_sw+0x9b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <Dswap2BArr@plt>
jmp    11e0 <fread_sw+0xa0>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_sw>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
call   1030 <fread@plt>
test   %ebx,%ebx
je     118f <fread_sw+0x4f>
cmp    $0x2,%ebp
je     1177 <fread_sw+0x37>
cmp    $0x4,%ebp
je     1184 <fread_sw+0x44>
cmp    $0x8,%ebp
jne    118f <fread_sw+0x4f>
mov    %r15,%rdi
mov    %r14d,%esi
call   1060 <Dswap8BArr@plt>
jmp    118f <fread_sw+0x4f>
mov    %r15,%rdi
mov    %r14d,%esi
call   1040 <Dswap2BArr@plt>
jmp    118f <fread_sw+0x4f>
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <Dswap4BArr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fread_sw(i8* %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = load i32*, i32** %9
%15 = call i32 @fread(i8* %11, i32 %12, i32 %13, i32* %14)
%16 = load i32, i32* %10
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %5
%19 = load i32, i32* %7
switch i32 %19, label %32 [
i32 8, label %20
i32 4, label %24
i32 2, label %28
]
20: ; preds = %18
%21 = load i8*, i8** %6
%22 = load i32, i32* %8
%23 = call i32 @Dswap8BArr(i8* %21, i32 %22)
br label %32
24: ; preds = %18
%25 = load i8*, i8** %6
%26 = load i32, i32* %8
%27 = call i32 @Dswap4BArr(i8* %25, i32 %26)
br label %32
28: ; preds = %18
%29 = load i8*, i8** %6
%30 = load i32, i32* %8
%31 = call i32 @Dswap2BArr(i8* %29, i32 %30)
br label %32
32: ; preds = %18, %28, %24, %20
br label %33
33: ; preds = %32, %5
ret i32 0
}

LLVM IR (-O2):
define i32 @fread_sw(i8* %0, i32 %1, i32 %2, i32* nocapture %3, i32 %4) {
%6 = tail call i32 @fread(i8* %0, i32 %1, i32 %2, i32* %3)
%7 = icmp eq i32 %4, 0
br i1 %7, label %15, label %8
8: ; preds = %5
switch i32 %1, label %15 [
i32 8, label %9
i32 4, label %11
i32 2, label %13
]
9: ; preds = %8
%10 = tail call i32 @Dswap8BArr(i8* %0, i32 %2)
br label %15
11: ; preds = %8
%12 = tail call i32 @Dswap4BArr(i8* %0, i32 %2)
br label %15
13: ; preds = %8
%14 = tail call i32 @Dswap2BArr(i8* %0, i32 %2)
br label %15
15: ; preds = %9, %11, %13, %8, %5
ret i32 0
}