#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 adc_chunk_type(unsigned char);
int adc_chunk_offset(unsigned char *chunk_start) {
  unsigned char *c = chunk_start;
  switch (adc_chunk_type(*c)) {
  case 0x01:
    return 0;
  case 0x02:
    return ((((unsigned char)*c & 0x03)) << 8) + (unsigned char)*(c + 1);
  case 0x03:
    return (((unsigned char)*(c + 1)) << 8) + (unsigned char)*(c + 2);
  }
  return -1;
}


x86 assembly (clang, -O0):
<adc_chunk_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <adc_chunk_type@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0x1,%eax
je     1165 <adc_chunk_offset+0x55>
jmp    1143 <adc_chunk_offset+0x33>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1171 <adc_chunk_offset+0x61>
jmp    1154 <adc_chunk_offset+0x44>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     1190 <adc_chunk_offset+0x80>
jmp    11ad <adc_chunk_offset+0x9d>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <adc_chunk_offset+0xa4>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
and    $0x3,%eax
shl    $0x8,%eax
mov    -0x18(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <adc_chunk_offset+0xa4>
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%eax
shl    $0x8,%eax
mov    -0x18(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <adc_chunk_offset+0xa4>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adc_chunk_offset>:
push   %rbx
mov    %rdi,%rbx
movzbl (%rdi),%edi
call   1030 <adc_chunk_type@plt>
cmp    $0x1,%eax
je     113c <adc_chunk_offset+0x2c>
cmp    $0x3,%eax
je     1140 <adc_chunk_offset+0x30>
cmp    $0x2,%eax
jne    114b <adc_chunk_offset+0x3b>
movzbl (%rbx),%ecx
and    $0x3,%ecx
shl    $0x8,%ecx
movzbl 0x1(%rbx),%eax
or     %ecx,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
movzwl 0x1(%rbx),%eax
shl    $0x10,%eax
bswap  %eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @adc_chunk_offset(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = call i32 @adc_chunk_type(i8 zeroext %7)
switch i32 %8, label %32 [
i32 1, label %9
i32 2, label %10
i32 3, label %21
]
9: ; preds = %1
store i32 0, i32* %2
br label %33
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = and i32 %13, 3
%15 = shl i32 %14, 8
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = add nsw i32 %15, %19
store i32 %20, i32* %2
br label %33
21: ; preds = %1
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = shl i32 %25, 8
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 2
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = add nsw i32 %26, %30
store i32 %31, i32* %2
br label %33
32: ; preds = %1
store i32 -1, i32* %2
br label %33
33: ; preds = %32, %21, %10, %9
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
define i32 @adc_chunk_offset(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @adc_chunk_type(i8 zeroext %2)
switch i32 %3, label %22 [
i32 1, label %23
i32 2, label %4
i32 3, label %13
]
4: ; preds = %1
%5 = load i8, i8* %0
%6 = and i8 %5, 3
%7 = zext i8 %6 to i32
%8 = shl nuw nsw i32 %7, 8
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = or i32 %8, %11
br label %23
13: ; preds = %1
%14 = getelementptr inbounds i8, i8* %0, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = getelementptr inbounds i8, i8* %0, i64 2
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = or i32 %17, %20
br label %23
22: ; preds = %1
br label %23
23: ; preds = %1, %22, %13, %4
%24 = phi i32 [ -1, %22 ], [ %21, %13 ], [ %12, %4 ], [ 0, %1 ]
ret i32 %24
}