#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);
int first_3_of_5(int value) {
  assert(value >= 0);
  if (value >= 100000)
    return value / 1000;
  if (value >= 10000)
    return value / 100;
  if (value >= 1000)
    return value / 10;
  return value;
}


x86 assembly (clang, -O0):
<first_3_of_5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x186a0,-0x8(%rbp)
jl     114c <first_3_of_5+0x3c>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1192 <first_3_of_5+0x82>
cmpl   $0x2710,-0x8(%rbp)
jl     116c <first_3_of_5+0x5c>
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1192 <first_3_of_5+0x82>
cmpl   $0x3e8,-0x8(%rbp)
jl     118c <first_3_of_5+0x7c>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1192 <first_3_of_5+0x82>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<first_3_of_5>:
push   %rbx
mov    %edi,%ebx
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
cmp    $0x186a0,%ebx
jl     1134 <first_3_of_5+0x24>
mov    %ebx,%eax
imul   $0x10624dd3,%rax,%rbx
shr    $0x26,%rbx
jmp    115f <first_3_of_5+0x4f>
cmp    $0x2710,%ebx
jl     114b <first_3_of_5+0x3b>
mov    %ebx,%eax
imul   $0x51eb851f,%rax,%rbx
shr    $0x25,%rbx
jmp    115f <first_3_of_5+0x4f>
cmp    $0x3e8,%ebx
jl     115f <first_3_of_5+0x4f>
movzwl %bx,%eax
imul   $0xcccd,%eax,%ebx
shr    $0x13,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @first_3_of_5(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sge i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i32, i32* %3
%9 = icmp sge i32 %8, 100000
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* %3
%12 = sdiv i32 %11, 1000
store i32 %12, i32* %2
br label %27
13: ; preds = %1
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 10000
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %3
%18 = sdiv i32 %17, 100
store i32 %18, i32* %2
br label %27
19: ; preds = %13
%20 = load i32, i32* %3
%21 = icmp sge i32 %20, 1000
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %3
%24 = sdiv i32 %23, 10
store i32 %24, i32* %2
br label %27
25: ; preds = %19
%26 = load i32, i32* %3
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %22, %16, %10
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @first_3_of_5(i32 %0) {
%2 = xor i32 %0, -1
%3 = lshr i32 %2, 31
%4 = tail call i32 @assert(i32 %3)
%5 = icmp sgt i32 %0, 99999
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = udiv i32 %0, 1000
br label %18
8: ; preds = %1
%9 = icmp sgt i32 %0, 9999
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = udiv i32 %0, 100
br label %18
12: ; preds = %8
%13 = icmp sgt i32 %0, 999
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = trunc i32 %0 to i16
%16 = udiv i16 %15, 10
%17 = zext i16 %16 to i32
br label %18
18: ; preds = %12, %14, %10, %6
%19 = phi i32 [ %7, %6 ], [ %11, %10 ], [ %17, %14 ], [ %0, %12 ]
ret i32 %19
}