#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 */
typedef int uint32_t;

/* Variables and functions */
scalar_t__ read_bit_PF();
uint32_t read_unsigned_value_PF(int n) {
  uint32_t ret = 0, mask = 1;
  for (int i = 0; i < n; i++) {
    if (read_bit_PF()) {
      ret |= mask;
    }
    mask <<= 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<read_unsigned_value_PF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    116d <read_unsigned_value_PF+0x5d>
mov    $0x0,%al
call   1030 <read_bit_PF@plt>
cmp    $0x0,%rax
je     1156 <read_unsigned_value_PF+0x46>
mov    -0xc(%rbp),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <read_unsigned_value_PF+0x20>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_unsigned_value_PF>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
jle    114f <read_unsigned_value_PF+0x3f>
mov    %edi,%r14d
mov    $0x1,%ebx
xor    %ebp,%ebp
jmp    113a <read_unsigned_value_PF+0x2a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
or     %ecx,%ebp
add    %ebx,%ebx
add    $0xffffffff,%r14d
je     1151 <read_unsigned_value_PF+0x41>
xor    %eax,%eax
call   1030 <read_bit_PF@plt>
mov    $0x0,%ecx
test   %rax,%rax
je     1130 <read_unsigned_value_PF+0x20>
mov    %ebx,%ecx
jmp    1130 <read_unsigned_value_PF+0x20>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_unsigned_value_PF(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %20, %1
%7 = load i32, i32* %5
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %23
10: ; preds = %6
%11 = call i64 (...) @read_bit_PF()
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = or i32 %15, %14
store i32 %16, i32* %3
br label %17
17: ; preds = %13, %10
%18 = load i32, i32* %4
%19 = shl i32 %18, 1
store i32 %19, i32* %4
br label %20
20: ; preds = %17
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %6
23: ; preds = %6
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @read_unsigned_value_PF(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %5, label %3
3: ; preds = %5, %1
%4 = phi i32 [ 0, %1 ], [ %12, %5 ]
ret i32 %4
5: ; preds = %1, %5
%6 = phi i32 [ %14, %5 ], [ 0, %1 ]
%7 = phi i32 [ %13, %5 ], [ 1, %1 ]
%8 = phi i32 [ %12, %5 ], [ 0, %1 ]
%9 = tail call i64 (...) @read_bit_PF()
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i32 0, i32 %7
%12 = or i32 %11, %8
%13 = shl i32 %7, 1
%14 = add nuw nsw i32 %6, 1
%15 = icmp eq i32 %14, %0
br i1 %15, label %3, label %5
}