int nrand48_r(xsubi, buffer, result)
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
mov    $0x0,%al
call   1030 <__drand48_iterate@plt>
cmp    $0x0,%eax
jge    1148 <nrand48_r+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    1171 <nrand48_r+0x61>
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   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <__drand48_iterate@plt>
test   %eax,%eax
js     113e <nrand48_r+0x2e>
movzwl 0x4(%rbx),%eax
shl    $0xf,%rax
movzwl 0x2(%rbx),%ecx
shr    %rcx
or     %rax,%rcx
mov    %rcx,(%r14)
jmp    1143 <nrand48_r+0x33>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.drand48_data = type opaque
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 i32 (i16*, %struct.drand48_data*, ...) bitcast (i32 (...)* @__drand48_iterate to i32 (i16*, %struct.drand48_data*, ...)*)(i16* %8, %struct.drand48_data* %9)
%11 = icmp slt i32 %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 opaque
define i32 @nrand48_r(i16* %0, %struct.drand48_data* %1, i64* nocapture writeonly %2) {
%4 = tail call i32 (i16*, %struct.drand48_data*, ...) bitcast (i32 (...)* @__drand48_iterate to i32 (i16*, %struct.drand48_data*, ...)*)(i16* %0, %struct.drand48_data* %1)
%5 = icmp slt i32 %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
}