#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);
unsigned int extract(char *s, int start, int length) {
  unsigned char cl;
  unsigned char cc;
  unsigned char cr;
  unsigned int x;
  assert(length <= 11);
  assert(start >= 0);
  assert(length >= 0);
  assert(start + length <= 66);
  cl = s[start / 8];
  cc = s[start / 8 + 1];
  cr = s[start / 8 + 2];
  x = ((int)(cl << 8 | cc) << 8 | cr);
  x = x >> (24 - (length + (start % 8)));
  x = (x & (0xffff >> (16 - length)));
  return (x);
}


x86 assembly (clang, -O0):
<extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0xb,-0x10(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x10(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    $0x42,%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x12(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x13(%rbp)
movzbl -0x11(%rbp),%eax
shl    $0x8,%eax
movzbl -0x12(%rbp),%ecx
or     %ecx,%eax
shl    $0x8,%eax
movzbl -0x13(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
mov    %edx,%ecx
mov    -0x1c(%rbp),%edx
add    %ecx,%edx
mov    $0x18,%ecx
sub    %edx,%ecx
shr    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
sub    -0x10(%rbp),%ecx
mov    $0xffff,%edx
sar    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
xor    %edi,%edi
cmp    $0xc,%edx
setl   %dil
call   1030 <assert@plt>
mov    %ebx,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
mov    %r14d,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
lea    (%r14,%rbx,1),%eax
xor    %edi,%edi
cmp    $0x43,%eax
setl   %dil
call   1030 <assert@plt>
lea    0x7(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
mov    %eax,%ecx
sar    $0x3,%ecx
movslq %ecx,%rcx
movzbl (%r15,%rcx,1),%esi
movzbl 0x1(%r15,%rcx,1),%edx
movzbl 0x2(%r15,%rcx,1),%ecx
shl    $0x10,%esi
shl    $0x8,%edx
or     %esi,%edx
or     %ecx,%edx
and    $0xfffffff8,%eax
sub    %eax,%ebx
add    %r14d,%ebx
mov    $0x18,%cl
sub    %bl,%cl
shr    %cl,%edx
mov    $0x10,%cl
sub    %r14b,%cl
mov    $0xffff,%eax
shr    %cl,%eax
and    %edx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @extract(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = icmp sle i32 %11, 11
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %5
%16 = icmp sge i32 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %6
%20 = icmp sge i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = add nsw i32 %23, %24
%26 = icmp sle i32 %25, 66
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i8*, i8** %4
%30 = load i32, i32* %5
%31 = sdiv i32 %30, 8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
store i8 %34, i8* %7
%35 = load i8*, i8** %4
%36 = load i32, i32* %5
%37 = sdiv i32 %36, 8
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %35, i64 %39
%41 = load i8, i8* %40
store i8 %41, i8* %8
%42 = load i8*, i8** %4
%43 = load i32, i32* %5
%44 = sdiv i32 %43, 8
%45 = add nsw i32 %44, 2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %42, i64 %46
%48 = load i8, i8* %47
store i8 %48, i8* %9
%49 = load i8, i8* %7
%50 = zext i8 %49 to i32
%51 = shl i32 %50, 8
%52 = load i8, i8* %8
%53 = zext i8 %52 to i32
%54 = or i32 %51, %53
%55 = shl i32 %54, 8
%56 = load i8, i8* %9
%57 = zext i8 %56 to i32
%58 = or i32 %55, %57
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = load i32, i32* %6
%61 = load i32, i32* %5
%62 = srem i32 %61, 8
%63 = add nsw i32 %60, %62
%64 = sub nsw i32 24, %63
%65 = lshr i32 %59, %64
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = load i32, i32* %6
%68 = sub nsw i32 16, %67
%69 = ashr i32 65535, %68
%70 = and i32 %66, %69
store i32 %70, i32* %10
%71 = load i32, i32* %10
ret i32 %71
}

LLVM IR (-O2):
define i32 @extract(i8* nocapture %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, 12
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = xor i32 %1, -1
%8 = lshr i32 %7, 31
%9 = tail call i32 @assert(i32 %8)
%10 = xor i32 %2, -1
%11 = lshr i32 %10, 31
%12 = tail call i32 @assert(i32 %11)
%13 = add nsw i32 %2, %1
%14 = icmp slt i32 %13, 67
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = sdiv i32 %1, 8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = add nsw i32 %17, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = add nsw i32 %17, 2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %20 to i32
%30 = zext i8 %24 to i32
%31 = shl nuw nsw i32 %29, 16
%32 = shl nuw nsw i32 %30, 8
%33 = or i32 %32, %31
%34 = zext i8 %28 to i32
%35 = or i32 %33, %34
%36 = srem i32 %1, 8
%37 = add i32 %36, %2
%38 = sub i32 24, %37
%39 = lshr i32 %35, %38
%40 = sub nsw i32 16, %2
%41 = lshr i32 65535, %40
%42 = and i32 %39, %41
ret i32 %42
}