#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 jrand48_r(unsigned short int xsubi[3], struct drand48_data *buffer,
              long int *result) {
  if (__drand48_iterate(xsubi, buffer) < 0)
    return -1;
  *result = ((xsubi[2] << 16) | xsubi[1]) & 0xffffffffl;
  return 0;
}


x86 assembly (clang, -O0):
<jrand48_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 <jrand48_r+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    117a <jrand48_r+0x6a>
mov    -0x10(%rbp),%rax
movzwl 0x4(%rax),%eax
shl    $0x10,%eax
mov    -0x10(%rbp),%rcx
movzwl 0x2(%rcx),%ecx
or     %ecx,%eax
movslq %eax,%rcx
movabs $0xffffffff,%rax
and    %rax,%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):
<jrand48_r>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
call   1030 <__drand48_iterate@plt>
test   %rax,%rax
js     112e <jrand48_r+0x1e>
mov    0x2(%rbx),%eax
mov    %rax,(%r14)
xor    %eax,%eax
jmp    1133 <jrand48_r+0x23>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.drand48_data = type { i32 }
define i32 @jrand48_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, 16
%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 = or i32 %18, %22
%24 = sext i32 %23 to i64
%25 = and i64 %24, 4294967295
%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 @jrand48_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 %15, 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, 16
%11 = getelementptr inbounds i16, i16* %0, i64 1
%12 = load i16, i16* %11
%13 = zext i16 %12 to i64
%14 = or i64 %10, %13
store i64 %14, i64* %2
br label %15
15: ; preds = %3, %6
%16 = phi i32 [ 0, %6 ], [ -1, %3 ]
ret i32 %16
}