#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*/ uint8_t;
typedef int uint64_t;

/* Variables and functions */
int __bswap_64(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
uint64_t bin2int(uint8_t *s, size_t len, int revert) {
  uint64_t a = 0;
  int l = (len <= sizeof a) ? len : sizeof a;
  memcpy((uint8_t *)&a, s, l);
  if (revert == 1)
    a = __bswap_64(a) >> 8 * (8 - l);
  return a;
}


x86 assembly (clang, -O0):
<bin2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x4,-0x10(%rbp)
ja     1152 <bin2int+0x32>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1160 <bin2int+0x40>
mov    $0x4,%eax
mov    %rax,-0x28(%rbp)
jmp    1160 <bin2int+0x40>
mov    -0x28(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x18(%rbp),%rdi
call   1040 <memcpy@plt>
cmpl   $0x1,-0x14(%rbp)
jne    1199 <bin2int+0x79>
mov    -0x18(%rbp),%edi
call   1030 <__bswap_64@plt>
mov    $0x8,%ecx
sub    -0x1c(%rbp),%ecx
shl    $0x3,%ecx
sar    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2int>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rax
movl   $0x0,0x4(%rsp)
cmp    $0x4,%rsi
mov    $0x4,%ebx
cmovb  %esi,%ebx
lea    0x4(%rsp),%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    0x4(%rsp),%eax
cmp    $0x1,%ebp
jne    1164 <bin2int+0x44>
mov    %eax,%edi
call   1030 <__bswap_64@plt>
shl    $0x3,%bl
neg    %bl
mov    %ebx,%ecx
sar    %cl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bin2int(i32* %0, i64 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%9 = load i64, i64* %5
%10 = icmp ule i64 %9, 4
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load i64, i64* %5
br label %14
13: ; preds = %3
br label %14
14: ; preds = %13, %11
%15 = phi i64 [ %12, %11 ], [ 4, %13 ]
%16 = trunc i64 %15 to i32
store i32 %16, i32* %8
%17 = load i32*, i32** %4
%18 = load i32, i32* %8
%19 = call i32 @memcpy(i32* %7, i32* %17, i32 %18)
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %29
22: ; preds = %14
%23 = load i32, i32* %7
%24 = call i32 @__bswap_64(i32 %23)
%25 = load i32, i32* %8
%26 = sub nsw i32 8, %25
%27 = mul nsw i32 8, %26
%28 = ashr i32 %24, %27
store i32 %28, i32* %7
br label %29
29: ; preds = %22, %14
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
define i32 @bin2int(i32* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%6 = icmp ult i64 %1, 4
%7 = select i1 %6, i64 %1, i64 4
%8 = trunc i64 %7 to i32
%9 = call i32 @memcpy(i32* %4, i32* %0, i32 %8)
%10 = icmp eq i32 %2, 1
%11 = load i32, i32* %4
br i1 %10, label %12, label %17
12: ; preds = %3
%13 = call i32 @__bswap_64(i32 %11)
%14 = mul nsw i32 %8, -8
%15 = add nsw i32 %14, 64
%16 = ashr i32 %13, %15
br label %17
17: ; preds = %3, %12
%18 = phi i32 [ %16, %12 ], [ %11, %3 ]
ret i32 %18
}