#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 /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int main(int argc, char *argv[]) {
  int fd = open("/dev/urandom", O_RDONLY);
  int i;
  char buf[256];
  int count = 4;
  if (fd < 0)
    return 1;
  if (argc == 2)
    count = atoi(argv[1]);
  for (i = 0; i < count; ++i)
    read(fd, buf, 256);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x4,-0x124(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1191 <main+0x51>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <main+0xb5>
cmpl   $0x2,-0x8(%rbp)
jne    11ae <main+0x6e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x124(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x124(%rbp),%eax
jge    11e6 <main+0xa6>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b5 <main+0x75>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xe9d(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11af <main+0x6f>
mov    %eax,%ebx
mov    $0x4,%ebp
cmp    $0x2,%r15d
jne    1188 <main+0x48>
mov    0x8(%r14),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11a4 <main+0x64>
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1040 <read@plt>
add    $0xffffffff,%ebp
jne    1190 <main+0x50>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
jmp    11b4 <main+0x74>
mov    $0x1,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%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
store i32 4, i32* %9
%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 %38
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %9
br label %23
23: ; preds = %18, %15
store i32 0, i32* %7
br label %24
24: ; preds = %32, %23
%25 = load i32, i32* %7
%26 = load i32, i32* %9
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = load i32, i32* %6
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 256)
br label %32
32: ; preds = %28
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %24
35: ; preds = %24
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %35, %14
%39 = load i32, i32* %3
ret i32 %39
}

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