#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ arc4random_buf(int *, size_t);
void randuuid(uint8_t *b, size_t n) {
  if (n > 16)
    n = 16;
  arc4random_buf(b, n);
  if (n > 8) {
    b[8] &= 0xbf;
    b[8] |= 0x80;
    b[6] &= 0x4f;
    b[6] |= 0x40;
  }
}


x86 assembly (clang, -O0):
<randuuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x10,-0x10(%rbp)
jbe    1133 <randuuid+0x23>
movq   $0x10,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <arc4random_buf@plt>
cmpq   $0x8,-0x10(%rbp)
jbe    1185 <randuuid+0x75>
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%ecx
and    $0xbf,%ecx
mov    %ecx,0x20(%rax)
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%ecx
or     $0x80,%ecx
mov    %ecx,0x20(%rax)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%ecx
and    $0x4f,%ecx
mov    %ecx,0x18(%rax)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%ecx
or     $0x40,%ecx
mov    %ecx,0x18(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randuuid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x10,%rsi
mov    $0x10,%ebx
cmovb  %rsi,%rbx
mov    %rbx,%rsi
call   1030 <arc4random_buf@plt>
cmp    $0x9,%rbx
jb     1151 <randuuid+0x41>
mov    0x18(%r14),%eax
mov    0x20(%r14),%ecx
and    $0x3f,%ecx
or     $0x80,%ecx
mov    %ecx,0x20(%r14)
and    $0xf,%eax
or     $0x40,%eax
mov    %eax,0x18(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @randuuid(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = icmp ugt i64 %5, 16
br i1 %6, label %7, label %8
7: ; preds = %2
store i64 16, i64* %4
br label %8
8: ; preds = %7, %2
%9 = load i32*, i32** %3
%10 = load i64, i64* %4
%11 = call i32 @arc4random_buf(i32* %9, i64 %10)
%12 = load i64, i64* %4
%13 = icmp ugt i64 %12, 8
br i1 %13, label %14, label %31
14: ; preds = %8
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 8
%17 = load i32, i32* %16
%18 = and i32 %17, 191
store i32 %18, i32* %16
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 8
%21 = load i32, i32* %20
%22 = or i32 %21, 128
store i32 %22, i32* %20
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 6
%25 = load i32, i32* %24
%26 = and i32 %25, 79
store i32 %26, i32* %24
%27 = load i32*, i32** %3
%28 = getelementptr inbounds i32, i32* %27, i64 6
%29 = load i32, i32* %28
%30 = or i32 %29, 64
store i32 %30, i32* %28
br label %31
31: ; preds = %14, %8
ret void
}

LLVM IR (-O2):
define void @randuuid(i32* %0, i64 %1) {
%3 = icmp ult i64 %1, 16
%4 = select i1 %3, i64 %1, i64 16
%5 = tail call i32 @arc4random_buf(i32* %0, i64 %4)
%6 = icmp ugt i64 %4, 8
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = getelementptr inbounds i32, i32* %0, i64 8
%9 = load i32, i32* %8
%10 = and i32 %9, 63
%11 = or i32 %10, 128
store i32 %11, i32* %8
%12 = getelementptr inbounds i32, i32* %0, i64 6
%13 = load i32, i32* %12
%14 = and i32 %13, 15
%15 = or i32 %14, 64
store i32 %15, i32* %12
br label %16
16: ; preds = %7, %2
ret void
}