#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 */
struct __sk_buff {
  scalar_t__ len;
};

/* Variables and functions */
__attribute__((section("socket"), used)) int
combinations(volatile struct __sk_buff *skb) {
  int ret = 0, i;
#pragma nounroll
  for (i = 0; i < 20; i++)
    if (skb->len)
      ret |= 1 << i;
  return ret;
}


x86 assembly (clang, -O0):
<combinations>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x14,-0x10(%rbp)
jge    1154 <combinations+0x54>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    $0x0,%rax
je     1141 <combinations+0x41>
mov    -0x10(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <combinations+0x46>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1116 <combinations+0x16>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<combinations>:
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%esi
shl    %cl,%esi
cmpq   $0x0,(%rdi)
cmove  %edx,%esi
or     %esi,%eax
add    $0x1,%ecx
cmp    $0x14,%ecx
jne    1110 <combinations+0x10>
ret

LLVM IR (-O0):
%struct.__sk_buff = type { i64 }
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @combinations to i8*)], section "llvm.metadata"
define i32 @combinations(%struct.__sk_buff* %0) section "socket" {
%2 = alloca %struct.__sk_buff*
%3 = alloca i32
%4 = alloca i32
store %struct.__sk_buff* %0, %struct.__sk_buff** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %19, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 20
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = load %struct.__sk_buff*, %struct.__sk_buff** %2
%10 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %9, i32 0, i32 0
%11 = load volatile i64, i64* %10
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* %4
%15 = shl i32 1, %14
%16 = load i32, i32* %3
%17 = or i32 %16, %15
store i32 %17, i32* %3
br label %18
18: ; preds = %13, %8
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %5
22: ; preds = %5
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.__sk_buff = type { i64 }
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @combinations to i8*)], section "llvm.metadata"
define i32 @combinations(%struct.__sk_buff* %0) section "socket" {
%2 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %0, i64 0, i32 0
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 0, %1 ], [ %11, %3 ]
%5 = phi i32 [ 0, %1 ], [ %10, %3 ]
%6 = load volatile i64, i64* %2
%7 = icmp eq i64 %6, 0
%8 = shl nuw nsw i32 1, %4
%9 = select i1 %7, i32 0, i32 %8
%10 = or i32 %9, %5
%11 = add nuw nsw i32 %4, 1
%12 = icmp eq i32 %11, 20
br i1 %12, label %13, label %3
13: ; preds = %3
ret i32 %10
}