#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 */
unsigned int get_figure(int, int /*<<< orphan*/);
int figure_top(int id) {
  unsigned int fig = get_figure(id, 0);
  unsigned int top = 10;
  for (int i = 0; i < 4 && top; ++i, fig >>= 4) {
    unsigned int y = ((fig >> 2) & 3);
    if (y < top)
      top = y;
  }
  return (signed)top;
}


x86 assembly (clang, -O0):
<figure_top>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <get_figure@plt>
mov    %eax,-0x8(%rbp)
movl   $0xa,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x4,-0x10(%rbp)
mov    %al,-0x15(%rbp)
jge    114f <figure_top+0x3f>
cmpl   $0x0,-0xc(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    115f <figure_top+0x4f>
jmp    1199 <figure_top+0x89>
mov    -0x8(%rbp),%eax
shr    $0x2,%eax
and    $0x3,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    117d <figure_top+0x6d>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <figure_top+0x72>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <figure_top+0x26>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<figure_top>:
push   %rax
xor    %esi,%esi
call   1030 <get_figure@plt>
mov    %eax,%ecx
shr    $0x2,%eax
and    $0x3,%eax
je     114f <figure_top+0x3f>
mov    %ecx,%edx
shr    $0x6,%edx
and    $0x3,%edx
cmp    %eax,%edx
cmovb  %edx,%eax
test   %eax,%eax
je     114f <figure_top+0x3f>
mov    %ecx,%edx
shr    $0xa,%edx
and    $0x3,%edx
cmp    %eax,%edx
cmovb  %edx,%eax
test   %eax,%eax
je     114f <figure_top+0x3f>
shr    $0xe,%ecx
and    $0x3,%ecx
cmp    %eax,%ecx
cmovb  %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @figure_top(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @get_figure(i32 %7, i32 0)
store i32 %8, i32* %3
store i32 10, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %27, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %12, %9
%16 = phi i1 [ false, %9 ], [ %14, %12 ]
br i1 %16, label %17, label %32
17: ; preds = %15
%18 = load i32, i32* %3
%19 = lshr i32 %18, 2
%20 = and i32 %19, 3
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = load i32, i32* %4
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = load i32, i32* %6
store i32 %25, i32* %4
br label %26
26: ; preds = %24, %17
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
%30 = load i32, i32* %3
%31 = lshr i32 %30, 4
store i32 %31, i32* %3
br label %9
32: ; preds = %15
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @figure_top(i32 %0) {
%2 = tail call i32 @get_figure(i32 %0, i32 0)
%3 = lshr i32 %2, 2
%4 = and i32 %3, 3
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %20, %14, %8, %1
%7 = phi i32 [ %4, %1 ], [ %12, %8 ], [ %18, %14 ], [ %24, %20 ]
ret i32 %7
8: ; preds = %1
%9 = lshr i32 %2, 6
%10 = and i32 %9, 3
%11 = icmp ult i32 %10, %4
%12 = select i1 %11, i32 %10, i32 %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %8
%15 = lshr i32 %2, 10
%16 = and i32 %15, 3
%17 = icmp ult i32 %16, %12
%18 = select i1 %17, i32 %16, i32 %12
%19 = icmp eq i32 %18, 0
br i1 %19, label %6, label %20
20: ; preds = %14
%21 = lshr i32 %2, 14
%22 = and i32 %21, 3
%23 = icmp ult i32 %22, %18
%24 = select i1 %23, i32 %22, i32 %18
br label %6
}