#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 */
typedef int /*<<< orphan*/ seed;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ errx(int, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, unsigned long *, int);
int /*<<< orphan*/ test567(int, unsigned long);
void test6(void) {
  int fd, len;
  unsigned long seed;
  printf("Beginning malloc test 6\n");
  fd = open("random:", O_RDONLY);
  if (fd < 0) {
    err(1, "%s", "random:");
  }
  len = read(fd, &seed, sizeof(seed));
  if (len < 0) {
    err(1, "%s", "random:");
  } else if (len < (int)sizeof(seed)) {
    errx(1, "%s: Short read", "random:");
  }
  close(fd);
  test567(6, seed);
}


x86 assembly (clang, -O0):
<test6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11be <test6+0x4e>
mov    $0x1,%edi
lea    0xe6f(%rip),%rsi
lea    0xe60(%rip),%rdx
call   1080 <err@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1070 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11f9 <test6+0x89>
mov    $0x1,%edi
lea    0xe39(%rip),%rsi
lea    0xe2a(%rip),%rdx
call   1080 <err@plt>
jmp    1220 <test6+0xb0>
cmpl   $0x8,-0x8(%rbp)
jge    121b <test6+0xab>
mov    $0x1,%edi
lea    0xe15(%rip),%rsi
lea    0xe03(%rip),%rdx
call   1040 <errx@plt>
jmp    1220 <test6+0xb0>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rsi
mov    $0x6,%edi
call   1030 <test567@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test6>:
push   %rbx
sub    $0x10,%rsp
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11b4 <test6+0x44>
lea    0xe65(%rip),%rsi
lea    0xe56(%rip),%rdx
mov    $0x1,%edi
call   1080 <err@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1070 <read@plt>
test   %eax,%eax
js     11e8 <test6+0x78>
cmp    $0x7,%eax
ja     1200 <test6+0x90>
lea    0xe36(%rip),%rsi
lea    0xe24(%rip),%rdx
mov    $0x1,%edi
call   1050 <errx@plt>
jmp    1200 <test6+0x90>
lea    0xe19(%rip),%rsi
lea    0xe0a(%rip),%rdx
mov    $0x1,%edi
call   1080 <err@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x8(%rsp),%rsi
mov    $0x6,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <test567@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Beginning malloc test 6\0A\00"
@.str.1 = [8 x i8] c"random:\00"
@O_RDONLY = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [15 x i8] c"%s: Short read\00"
define void @test6() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = load i32, i32* %1
%13 = call i32 @read(i32 %12, i64* %3, i32 8)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %24
18: ; preds = %11
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @errx(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
br label %24
24: ; preds = %23, %16
%25 = load i32, i32* %1
%26 = call i32 @close(i32 %25)
%27 = load i64, i64* %3
%28 = call i32 @test567(i32 6, i64 %27)
ret void
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"random:\00"
@O_RDONLY = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [15 x i8] c"%s: Short read\00"
@str = [24 x i8] c"Beginning malloc test 6\00"
define void @test6() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32 @read(i32 %5, i64* %1, i32 8)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %18
14: ; preds = %9
%15 = icmp ult i32 %10, 8
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %14, %16, %12
%19 = tail call i32 @close(i32 %5)
%20 = load i64, i64* %1
%21 = tail call i32 @test567(i32 6, i64 %20)
ret void
}