#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char *argv[]) {
  int i;
  int n;
  char random[1024];
  if (argc <= 1)
    n = 10;
  else {
    sscanf(argv[1], "%d", &n);
    if (n < 0 || n > 65536)
      n = 10;
  }
  FILE *rnd = fopen("/dev/urandom", "r");
  while (n > 0) {
    fread(&random, 1024, 1, rnd);
    for (i = 0; i < (n > 1024 ? 1024 : n); i++)
      printf("%.2x", (unsigned char)random[i]);
    n -= 1024;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     116f <main+0x2f>
movl   $0xa,-0x18(%rbp)
jmp    11aa <main+0x6a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe82(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
cmpl   $0x0,-0x18(%rbp)
jl     119e <main+0x5e>
cmpl   $0x10000,-0x18(%rbp)
jle    11a5 <main+0x65>
movl   $0xa,-0x18(%rbp)
jmp    11aa <main+0x6a>
lea    0xe52(%rip),%rdi
lea    0xe58(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    126b <main+0x12b>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rcx
mov    $0x400,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x42c(%rbp)
cmpl   $0x400,-0x18(%rbp)
jle    1218 <main+0xd8>
mov    $0x400,%eax
mov    %eax,-0x430(%rbp)
jmp    1221 <main+0xe1>
mov    -0x18(%rbp),%eax
mov    %eax,-0x430(%rbp)
mov    -0x42c(%rbp),%eax
mov    -0x430(%rbp),%ecx
cmp    %ecx,%eax
jge    125b <main+0x11b>
movslq -0x14(%rbp),%rax
lea    0xdd2(%rip),%rdi
movzbl -0x420(%rbp,%rax,1),%esi
ff
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f2 <main+0xb2>
mov    -0x18(%rbp),%eax
sub    $0x400,%eax
mov    %eax,-0x18(%rbp)
jmp    11c4 <main+0x84>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x418,%rsp
cmp    $0x1,%edi
jle    1172 <main+0x32>
mov    0x8(%rsi),%rdi
lea    0xea2(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
cmpl   $0x10001,0xc(%rsp)
jb     117a <main+0x3a>
movl   $0xa,0xc(%rsp)
lea    0xe82(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
cmpl   $0x0,0xc(%rsp)
jle    120b <main+0xcb>
mov    %rax,%r15
lea    0x10(%rsp),%r14
lea    0xe6f(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
cmpl   $0x0,0xc(%rsp)
jle    120b <main+0xcb>
xor    %ebx,%ebx
xchg   %ax,%ax
movzbl 0x10(%rsp,%rbx,1),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
mov    0xc(%rsp),%eax
cmp    $0x400,%eax
mov    $0x400,%ecx
cmovl  %eax,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rbx
jl     11d0 <main+0x90>
lea    -0x400(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0x400,%eax
jg     11b0 <main+0x70>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"/dev/urandom\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"%.2x\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 10, i32* %7
br label %25
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %13
%21 = load i32, i32* %7
%22 = icmp sgt i32 %21, 65536
br i1 %22, label %23, label %24
23: ; preds = %20, %13
store i32 10, i32* %7
br label %24
24: ; preds = %23, %20
br label %25
25: ; preds = %24, %12
%26 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %26, i32** %9
br label %27
27: ; preds = %53, %25
%28 = load i32, i32* %7
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %56
30: ; preds = %27
%31 = bitcast [1024 x i8]* %8 to i8**
%32 = load i32*, i32** %9
%33 = call i32 @fread(i8** %31, i32 1024, i32 1, i32* %32)
store i32 0, i32* %6
br label %34
34: ; preds = %50, %30
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = icmp sgt i32 %36, 1024
br i1 %37, label %38, label %39
38: ; preds = %34
br label %41
39: ; preds = %34
%40 = load i32, i32* %7
br label %41
41: ; preds = %39, %38
%42 = phi i32 [ 1024, %38 ], [ %40, %39 ]
%43 = icmp slt i32 %35, %42
br i1 %43, label %44, label %53
44: ; preds = %41
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %48)
br label %50
50: ; preds = %44
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %34
53: ; preds = %41
%54 = load i32, i32* %7
%55 = sub nsw i32 %54, 1024
store i32 %55, i32* %7
br label %27
56: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"/dev/urandom\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"%.2x\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 10, i32* %3
br label %16
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
%14 = icmp ugt i32 %13, 65536
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 10, i32* %3
br label %16
16: ; preds = %15, %9, %8
%17 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = bitcast [1024 x i8]* %4 to i8**
br label %22
22: ; preds = %20, %37
%23 = call i32 @fread(i8** %21, i32 1024, i32 1, i32* %17)
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %22, %26
%27 = phi i64 [ %31, %26 ], [ 0, %22 ]
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %29)
%31 = add nuw nsw i64 %27, 1
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 1024
%34 = select i1 %33, i32 %32, i32 1024
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %31, %35
br i1 %36, label %26, label %37
37: ; preds = %26
%38 = add nsw i32 %32, -1024
store i32 %38, i32* %3
%39 = icmp sgt i32 %32, 1024
br i1 %39, label %22, label %40
40: ; preds = %37, %22, %16
ret i32 0
}