#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 */

/* Variables and functions */
int rand();
void generate_seg(unsigned long long *poffset, unsigned long *plen) {
  unsigned long long offset;
  unsigned long len;
  offset = rand() % (4 * (8 / (2) * sizeof(unsigned long)));
  len = rand() % (8) + 1;
  if ((offset + len) > (4 * (8 / (2) * sizeof(unsigned long))))
    len = (4 * (8 / (2) * sizeof(unsigned long))) - offset;
  *poffset = offset;
  *plen = len;
}


x86 assembly (clang, -O0):
<generate_seg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
cltq
and    $0x7f,%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq %edx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
cmp    $0x80,%rax
jbe    116b <generate_seg+0x5b>
mov    $0x80,%eax
sub    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_seg>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <rand@plt>
mov    %eax,%ebx
and    $0x7f,%ebx
xor    %eax,%eax
call   1030 <rand@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff8,%ecx
sub    %ecx,%eax
cltq
lea    (%rax,%rbx,1),%rcx
add    $0x1,%rcx
add    $0x1,%rax
mov    $0x80,%edx
sub    %rbx,%rdx
cmp    $0x81,%rcx
cmovb  %rax,%rdx
mov    %rbx,(%r15)
mov    %rdx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @generate_seg(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64
store i64* %0, i64** %3
store i64* %1, i64** %4
%7 = call i32 (...) @rand()
%8 = sext i32 %7 to i64
%9 = urem i64 %8, 128
store i64 %9, i64* %5
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 8
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
store i64 %13, i64* %6
%14 = load i64, i64* %5
%15 = load i64, i64* %6
%16 = add i64 %14, %15
%17 = icmp ugt i64 %16, 128
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i64, i64* %5
%20 = sub i64 128, %19
store i64 %20, i64* %6
br label %21
21: ; preds = %18, %2
%22 = load i64, i64* %5
%23 = load i64*, i64** %3
store i64 %22, i64* %23
%24 = load i64, i64* %6
%25 = load i64*, i64** %4
store i64 %24, i64* %25
ret void
}

LLVM IR (-O2):
define void @generate_seg(i64* nocapture writeonly %0, i64* nocapture writeonly %1) {
%3 = tail call i32 (...) @rand()
%4 = and i32 %3, 127
%5 = zext i32 %4 to i64
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 8
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = add nsw i64 %9, %5
%11 = icmp ugt i64 %10, 128
%12 = sub nuw nsw i64 128, %5
%13 = select i1 %11, i64 %12, i64 %9
store i64 %5, i64* %0
store i64 %13, i64* %1
ret void
}