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

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, size_t);
int touch_anon(char *buf, size_t size) {
  int fd;
  char *pos = buf;
  fd = open("/dev/urandom", O_RDONLY);
  if (fd < 0)
    return -1;
  while (size > 0) {
    ssize_t ret = read(fd, pos, size);
    if (ret < 0) {
      if (errno != EINTR) {
        close(fd);
        return -1;
      }
    } else {
      pos += ret;
      size -= ret;
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<touch_anon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1176 <touch_anon+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <touch_anon+0xd7>
jmp    117b <touch_anon+0x4b>
cmpq   $0x0,-0x18(%rbp)
jbe    11f8 <touch_anon+0xc8>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <read@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    11d8 <touch_anon+0xa8>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%rax
je     11d3 <touch_anon+0xa3>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <touch_anon+0xd7>
jmp    11f3 <touch_anon+0xc3>
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    117b <touch_anon+0x4b>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<touch_anon>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11b8 <touch_anon+0x88>
mov    %eax,%r15d
xor    %r14d,%r14d
test   %rbx,%rbx
je     11ae <touch_anon+0x7e>
mov    0x2e6c(%rip),%r12
mov    0x2e5d(%rip),%r13
jmp    118b <touch_anon+0x5b>
cs nopw 0x0(%rax,%rax,1)
nop
add    %rax,%rbp
sub    %rax,%rbx
test   %rbx,%rbx
je     11ae <touch_anon+0x7e>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <read@plt>
test   %rax,%rax
jns    1180 <touch_anon+0x50>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1186 <touch_anon+0x56>
mov    $0xffffffff,%r14d
mov    %r15d,%edi
call   1030 <close@plt>
jmp    11be <touch_anon+0x8e>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @touch_anon(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = load i8*, i8** %4
store i8* %9, i8** %7
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %45
15: ; preds = %2
br label %16
16: ; preds = %41, %15
%17 = load i64, i64* %5
%18 = icmp ugt i64 %17, 0
br i1 %18, label %19, label %42
19: ; preds = %16
%20 = load i32, i32* %6
%21 = load i8*, i8** %7
%22 = load i64, i64* %5
%23 = call i64 @read(i32 %20, i8* %21, i64 %22)
store i64 %23, i64* %8
%24 = load i64, i64* %8
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %19
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINTR
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
store i32 -1, i32* %3
br label %45
33: ; preds = %26
br label %41
34: ; preds = %19
%35 = load i64, i64* %8
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i64 %35
store i8* %37, i8** %7
%38 = load i64, i64* %8
%39 = load i64, i64* %5
%40 = sub i64 %39, %38
store i64 %40, i64* %5
br label %41
41: ; preds = %34, %33
br label %16
42: ; preds = %16
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
store i32 0, i32* %3
br label %45
45: ; preds = %42, %30, %14
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @touch_anon(i8* nocapture %0, i64 %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %27, label %6
6: ; preds = %2
%7 = icmp eq i64 %1, 0
br i1 %7, label %24, label %8
8: ; preds = %6, %20
%9 = phi i8* [ %22, %20 ], [ %0, %6 ]
%10 = phi i64 [ %21, %20 ], [ %1, %6 ]
%11 = tail call i64 @read(i32 %4, i8* %9, i64 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %20, label %24
17: ; preds = %8
%18 = getelementptr inbounds i8, i8* %9, i64 %11
%19 = sub i64 %10, %11
br label %20
20: ; preds = %17, %13
%21 = phi i64 [ %10, %13 ], [ %19, %17 ]
%22 = phi i8* [ %9, %13 ], [ %18, %17 ]
%23 = icmp eq i64 %21, 0
br i1 %23, label %24, label %8
24: ; preds = %20, %13, %6
%25 = phi i32 [ 0, %6 ], [ -1, %13 ], [ 0, %20 ]
%26 = tail call i32 @close(i32 %4)
br label %27
27: ; preds = %24, %2
%28 = phi i32 [ -1, %2 ], [ %25, %24 ]
ret i32 %28
}