#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 */
scalar_t__ nr_iowait_cpu(int /*<<< orphan*/);
int /*<<< orphan*/ smp_processor_id();
int which_bucket(unsigned int duration) {
  int bucket = 0;
  if (nr_iowait_cpu(smp_processor_id()))
    bucket = 12 / 2;
  if (duration < 10)
    return bucket;
  if (duration < 100)
    return bucket + 1;
  if (duration < 1000)
    return bucket + 2;
  if (duration < 10000)
    return bucket + 3;
  if (duration < 100000)
    return bucket + 4;
  return bucket + 5;
}


x86 assembly (clang, -O0):
<which_bucket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <smp_processor_id@plt>
mov    %eax,%edi
call   1040 <nr_iowait_cpu@plt>
cmp    $0x0,%rax
je     1151 <which_bucket+0x31>
movl   $0x6,-0xc(%rbp)
cmpl   $0xa,-0x8(%rbp)
jae    1166 <which_bucket+0x46>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <which_bucket+0xb8>
cmpl   $0x64,-0x8(%rbp)
jae    117e <which_bucket+0x5e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <which_bucket+0xb8>
cmpl   $0x3e8,-0x8(%rbp)
jae    1199 <which_bucket+0x79>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <which_bucket+0xb8>
cmpl   $0x2710,-0x8(%rbp)
jae    11b4 <which_bucket+0x94>
mov    -0xc(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <which_bucket+0xb8>
cmpl   $0x186a0,-0x8(%rbp)
jae    11cf <which_bucket+0xaf>
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <which_bucket+0xb8>
mov    -0xc(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<which_bucket>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <smp_processor_id@plt>
mov    %eax,%edi
call   1040 <nr_iowait_cpu@plt>
test   %rax,%rax
mov    $0x6,%eax
cmove  %ebp,%eax
cmp    $0xa,%ebx
jb     1179 <which_bucket+0x59>
cmp    $0x63,%ebx
ja     114f <which_bucket+0x2f>
or     $0x1,%eax
jmp    1179 <which_bucket+0x59>
cmp    $0x3e7,%ebx
ja     115c <which_bucket+0x3c>
add    $0x2,%eax
jmp    1179 <which_bucket+0x59>
cmp    $0x270f,%ebx
ja     1169 <which_bucket+0x49>
add    $0x3,%eax
jmp    1179 <which_bucket+0x59>
cmp    $0x1869f,%ebx
ja     1176 <which_bucket+0x56>
add    $0x4,%eax
jmp    1179 <which_bucket+0x59>
add    $0x5,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @which_bucket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%5 = call i32 (...) @smp_processor_id()
%6 = call i64 @nr_iowait_cpu(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 6, i32* %4
br label %9
9: ; preds = %8, %1
%10 = load i32, i32* %3
%11 = icmp ult i32 %10, 10
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i32, i32* %4
store i32 %13, i32* %2
br label %41
14: ; preds = %9
%15 = load i32, i32* %3
%16 = icmp ult i32 %15, 100
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %41
20: ; preds = %14
%21 = load i32, i32* %3
%22 = icmp ult i32 %21, 1000
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 2
store i32 %25, i32* %2
br label %41
26: ; preds = %20
%27 = load i32, i32* %3
%28 = icmp ult i32 %27, 10000
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 3
store i32 %31, i32* %2
br label %41
32: ; preds = %26
%33 = load i32, i32* %3
%34 = icmp ult i32 %33, 100000
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 4
store i32 %37, i32* %2
br label %41
38: ; preds = %32
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 5
store i32 %40, i32* %2
br label %41
41: ; preds = %38, %35, %29, %23, %17, %12
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
define i32 @which_bucket(i32 %0) {
%2 = tail call i32 (...) @smp_processor_id()
%3 = tail call i64 @nr_iowait_cpu(i32 %2)
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i32 0, i32 6
%6 = icmp ult i32 %0, 10
br i1 %6, label %25, label %7
7: ; preds = %1
%8 = icmp ult i32 %0, 100
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = or i32 %5, 1
br label %25
11: ; preds = %7
%12 = icmp ult i32 %0, 1000
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = add nuw nsw i32 %5, 2
br label %25
15: ; preds = %11
%16 = icmp ult i32 %0, 10000
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = add nuw nsw i32 %5, 3
br label %25
19: ; preds = %15
%20 = icmp ult i32 %0, 100000
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = add nuw nsw i32 %5, 4
br label %25
23: ; preds = %19
%24 = add nuw nsw i32 %5, 5
br label %25
25: ; preds = %1, %23, %21, %17, %13, %9
%26 = phi i32 [ %10, %9 ], [ %14, %13 ], [ %18, %17 ], [ %22, %21 ], [ %24, %23 ], [ %5, %1 ]
ret i32 %26
}