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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x4,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118b <main+0x4b>
movl   $0x1,-0x4(%rbp)
jmp    11bf <main+0x7f>
cmpl   $0x2,-0x8(%rbp)
jne    11a5 <main+0x65>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <urandom_read@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     118b <main+0x4b>
mov    %eax,%ebx
mov    $0x4,%esi
cmp    $0x2,%ebp
jne    1179 <main+0x39>
mov    0x8(%r14),%rdi
call   1060 <atoi@plt>
mov    %eax,%esi
mov    %ebx,%edi
call   1040 <urandom_read@plt>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
jmp    1190 <main+0x50>
mov    $0x1,%eax
pop    %rbx
pop    %r14
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
store i32 4, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %27
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %7
br label %21
21: ; preds = %16, %13
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = call i32 @urandom_read(i32 %22, i32 %23)
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
store i32 0, i32* %3
br label %27
27: ; preds = %21, %12
%28 = load i32, i32* %3
ret i32 %28
}

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 = 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 %16, label %6
6: ; preds = %2
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ %11, %8 ], [ 4, %6 ]
%14 = tail call i32 @urandom_read(i32 %4, i32 %13)
%15 = tail call i32 @close(i32 %4)
br label %16
16: ; preds = %2, %12
%17 = phi i32 [ 0, %12 ], [ 1, %2 ]
ret i32 %17
}