#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;
};
typedef long int32_t;

/* 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 = (int32_t)((xsubi[2] << 16) | xsubi[1]);
  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    116d <__jrand48_r+0x5d>
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
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     113b <__jrand48_r+0x2b>
movzwl 0x4(%rbx),%eax
shl    $0x10,%eax
movzwl 0x2(%rbx),%ecx
cltq
or     %rcx,%rax
mov    %rax,(%r14)
xor    %eax,%eax
jmp    1140 <__jrand48_r+0x30>
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 %26
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 = load i64*, i64** %7
store i64 %24, i64* %25
store i32 0, i32* %4
br label %26
26: ; preds = %13, %12
%27 = load i32, i32* %4
ret i32 %27
}

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 %16, label %6
6: ; preds = %3
%7 = getelementptr inbounds i16, i16* %0, i64 2
%8 = load i16, i16* %7
%9 = zext i16 %8 to i32
%10 = shl nuw i32 %9, 16
%11 = getelementptr inbounds i16, i16* %0, i64 1
%12 = load i16, i16* %11
%13 = zext i16 %12 to i32
%14 = or i32 %10, %13
%15 = sext i32 %14 to i64
store i64 %15, i64* %2
br label %16
16: ; preds = %3, %6
%17 = phi i32 [ 0, %6 ], [ -1, %3 ]
ret i32 %17
}