#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 */
struct drand48_data {
  int dummy;
};

/* Variables and functions */
scalar_t__ __drand48_iterate(unsigned short *, struct drand48_data *);
int nrand48_r(unsigned short int xsubi[3], struct drand48_data *buffer,
              long int *result) {
  if (__drand48_iterate(xsubi, buffer) < 0)
    return -1;
  if (sizeof(unsigned short int) == 2)
    *result = xsubi[2] << 15 | xsubi[1] >> 1;
  else
    *result = xsubi[2] >> 1;
  return 0;
}


x86 assembly (clang, -O0):
<nrand48_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <__drand48_iterate@plt>
cmp    $0x0,%rax
jge    1147 <nrand48_r+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    1170 <nrand48_r+0x60>
mov    -0x10(%rbp),%rax
movzwl 0x4(%rax),%eax
shl    $0xf,%eax
mov    -0x10(%rbp),%rcx
movzwl 0x2(%rcx),%ecx
sar    $0x1,%ecx
or     %ecx,%eax
movslq %eax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nrand48_r>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
call   1030 <__drand48_iterate@plt>
test   %rax,%rax
js     113d <nrand48_r+0x2d>
movzwl 0x4(%rbx),%eax
shl    $0xf,%rax
movzwl 0x2(%rbx),%ecx
shr    %rcx
or     %rax,%rcx
mov    %rcx,(%r14)
xor    %eax,%eax
jmp    1142 <nrand48_r+0x32>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.drand48_data = type { i32 }
define i32 @nrand48_r(i16* %0, %struct.drand48_data* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i16*
%6 = alloca %struct.drand48_data*
%7 = alloca i64*
store i16* %0, i16** %5
store %struct.drand48_data* %1, %struct.drand48_data** %6
store i64* %2, i64** %7
%8 = load i16*, i16** %5
%9 = load %struct.drand48_data*, %struct.drand48_data** %6
%10 = call i64 @__drand48_iterate(i16* %8, %struct.drand48_data* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %27
13: ; preds = %3
%14 = load i16*, i16** %5
%15 = getelementptr inbounds i16, i16* %14, i64 2
%16 = load i16, i16* %15
%17 = zext i16 %16 to i32
%18 = shl i32 %17, 15
%19 = load i16*, i16** %5
%20 = getelementptr inbounds i16, i16* %19, i64 1
%21 = load i16, i16* %20
%22 = zext i16 %21 to i32
%23 = ashr i32 %22, 1
%24 = or i32 %18, %23
%25 = sext i32 %24 to i64
%26 = load i64*, i64** %7
store i64 %25, i64* %26
store i32 0, i32* %4
br label %27
27: ; preds = %13, %12
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
%struct.drand48_data = type { i32 }
define i32 @nrand48_r(i16* %0, %struct.drand48_data* %1, i64* nocapture writeonly %2) {
%4 = tail call i64 @__drand48_iterate(i16* %0, %struct.drand48_data* %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = getelementptr inbounds i16, i16* %0, i64 2
%8 = load i16, i16* %7
%9 = zext i16 %8 to i64
%10 = shl nuw nsw i64 %9, 15
%11 = getelementptr inbounds i16, i16* %0, i64 1
%12 = load i16, i16* %11
%13 = lshr i16 %12, 1
%14 = zext i16 %13 to i64
%15 = or i64 %10, %14
store i64 %15, i64* %2
br label %16
16: ; preds = %3, %6
%17 = phi i32 [ 0, %6 ], [ -1, %3 ]
ret i32 %17
}