#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int XTeaGenerateIVec(unsigned char ivec[8]) {
  int fd = open("/dev/urandom", O_RDONLY);
  if (fd < 0) {
    return -1;
  }
  ssize_t ret = read(fd, ivec, 8);
  close(fd);
  return ret == 8 ? 0 : -1;
}


x86 assembly (clang, -O0):
<XTeaGenerateIVec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
lea    0xeb4(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    116a <XTeaGenerateIVec+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <XTeaGenerateIVec+0x69>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x8,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XTeaGenerateIVec>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    0xeba(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1175 <XTeaGenerateIVec+0x45>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
cmp    $0x8,%ebx
setne  %al
neg    %eax
jmp    117a <XTeaGenerateIVec+0x4a>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @XTeaGenerateIVec(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %21
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i8*, i8** %3
%14 = call i32 @read(i32 %12, i8* %13, i32 8)
store i32 %14, i32* %5
%15 = load i32, i32* %4
%16 = call i32 @close(i32 %15)
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 8
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 0, i32 -1
store i32 %20, i32* %2
br label %21
21: ; preds = %11, %10
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @XTeaGenerateIVec(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i32 @read(i32 %3, i8* %0, i32 8)
%7 = tail call i32 @close(i32 %3)
%8 = icmp ne i32 %6, 8
%9 = sext i1 %8 to i32
br label %10
10: ; preds = %1, %5
%11 = phi i32 [ %9, %5 ], [ -1, %1 ]
ret i32 %11
}