char lzmadec_header_dictionary(unsigned int *size,
                               const unsigned char *buffer) {
  unsigned int i;
  *size = 0;
  for (i = 0; i < 4; i++)
    *size += (unsigned int)(*buffer++) << (i * 8);
  if (*size > (1 << 28))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<lzmadec_header_dictionary>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jae    1159 <lzmadec_header_dictionary+0x59>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movzbl (%rax),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    111d <lzmadec_header_dictionary+0x1d>
mov    -0x10(%rbp),%rax
cmpl   $0x10000000,(%rax)
jbe    1172 <lzmadec_header_dictionary+0x72>
movb   $0xff,-0x1(%rbp)
jmp    1176 <lzmadec_header_dictionary+0x76>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<lzmadec_header_dictionary>:
movl   $0x0,(%rdi)
movzbl (%rsi),%eax
mov    %eax,(%rdi)
movzbl 0x1(%rsi),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
mov    %ecx,(%rdi)
movzbl 0x2(%rsi),%eax
shl    $0x10,%eax
or     %ecx,%eax
mov    %eax,(%rdi)
movzbl 0x3(%rsi),%ecx
shl    $0x18,%ecx
or     %eax,%ecx
mov    %ecx,(%rdi)
xor    %eax,%eax
cmp    $0x10000001,%ecx
adc    $0xff,%al
ret

LLVM IR (-O0):
define signext i8 @lzmadec_header_dictionary(i32* %0, i8* %1) {
%3 = alloca i8
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%7 = load i32*, i32** %4
store i32 0, i32* %7
store i32 0, i32* %6
br label %8
8: ; preds = %22, %2
%9 = load i32, i32* %6
%10 = icmp ult i32 %9, 4
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
%14 = load i8, i8* %12
%15 = zext i8 %14 to i32
%16 = load i32, i32* %6
%17 = mul i32 %16, 8
%18 = shl i32 %15, %17
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = add i32 %20, %18
store i32 %21, i32* %19
br label %22
22: ; preds = %11
%23 = load i32, i32* %6
%24 = add i32 %23, 1
store i32 %24, i32* %6
br label %8
25: ; preds = %8
%26 = load i32*, i32** %4
%27 = load i32, i32* %26
%28 = icmp ugt i32 %27, 268435456
br i1 %28, label %29, label %30
29: ; preds = %25
store i8 -1, i8* %3
br label %31
30: ; preds = %25
store i8 0, i8* %3
br label %31
31: ; preds = %30, %29
%32 = load i8, i8* %3
ret i8 %32
}

LLVM IR (-O2):
define signext i8 @lzmadec_header_dictionary(i32* nocapture %0, i8* nocapture %1) {
store i32 0, i32* %0
%3 = getelementptr inbounds i8, i8* %1, i64 1
%4 = load i8, i8* %1
%5 = zext i8 %4 to i32
store i32 %5, i32* %0
%6 = getelementptr inbounds i8, i8* %1, i64 2
%7 = load i8, i8* %3
%8 = zext i8 %7 to i32
%9 = shl nuw nsw i32 %8, 8
%10 = or i32 %9, %5
store i32 %10, i32* %0
%11 = getelementptr inbounds i8, i8* %1, i64 3
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = shl nuw nsw i32 %13, 16
%15 = or i32 %14, %10
store i32 %15, i32* %0
%16 = load i8, i8* %11
%17 = zext i8 %16 to i32
%18 = shl nuw i32 %17, 24
%19 = or i32 %18, %15
store i32 %19, i32* %0
%20 = icmp ugt i32 %19, 268435456
%21 = sext i1 %20 to i8
ret i8 %21
}