#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned int **, int, int, int /*<<< orphan*/ *);
unsigned int power10(int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char *argv[]) {
  int i;
  int n;
  int d;
  unsigned int random[1024];
  if (argc <= 1) {
    d = 10;
    n = d / 9 + 1;
  } else {
    sscanf(argv[1], "%d", &d);
    n = d / 9 + 1;
    if (n < 1 || n > 65536 || d < 0) {
      d = 10;
      n = d / 9 + 1;
    }
  }
  FILE *rnd = fopen("/dev/urandom", "r");
  while (n > 0) {
    fread(&random, 1024, sizeof(unsigned int), rnd);
    for (i = 0; i < (n > 1024 ? 1024 : n) && d > 0; i++)
      if (random[i] < 4000000000u) {
        if (d < 9) {
          char format[8];
          sprintf((char *)format, "%%0%du", d);
          printf(format, random[i] % power10(d));
        } else
          printf("%09u", random[i] % ((unsigned int)1000000000));
        d -= 9;
      } else
        n++;
    n -= 1024;
  }
  fclose(rnd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11b0 <main+0x40>
movl   $0xa,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1217 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe41(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jl     11fa <main+0x8a>
cmpl   $0x10000,-0x18(%rbp)
jg     11fa <main+0x8a>
cmpl   $0x0,-0x1c(%rbp)
jge    1212 <main+0xa2>
movl   $0xa,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1217 <main+0xa7>
lea    0xde5(%rip),%rdi
lea    0xdeb(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x1028(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    13a1 <main+0x231>
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rcx
mov    $0x400,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1034(%rbp)
cmpl   $0x400,-0x18(%rbp)
jle    1285 <main+0x115>
mov    $0x400,%eax
mov    %eax,-0x1038(%rbp)
jmp    128e <main+0x11e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1038(%rbp)
mov    -0x1034(%rbp),%ecx
mov    -0x1038(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1039(%rbp)
jge    12b7 <main+0x147>
cmpl   $0x0,-0x1c(%rbp)
setg   %al
mov    %al,-0x1039(%rbp)
mov    -0x1039(%rbp),%al
test   $0x1,%al
jne    12ca <main+0x15a>
jmp    1391 <main+0x221>
movslq -0x14(%rbp),%rax
cmpl   $0xee6b2800,-0x1020(%rbp,%rax,4)
jae    1375 <main+0x205>
cmpl   $0x9,-0x1c(%rbp)
jge    1345 <main+0x1d5>
lea    -0x1030(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd18(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1048(%rbp)
movslq -0x14(%rbp),%rax
mov    -0x1020(%rbp,%rax,4),%eax
mov    %eax,-0x1040(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <power10@plt>
mov    -0x1048(%rbp),%rdi
mov    %eax,%ecx
mov    -0x1040(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %edx,%esi
call   1050 <printf@plt>
jmp    1367 <main+0x1f7>
movslq -0x14(%rbp),%rax
mov    -0x1020(%rbp,%rax,4),%eax
mov    $0x3b9aca00,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%esi
lea    0xcb7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
sub    $0x9,%eax
mov    %eax,-0x1c(%rbp)
jmp    137e <main+0x20e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1383 <main+0x213>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    125f <main+0xef>
mov    -0x18(%rbp),%eax
sub    $0x400,%eax
mov    %eax,-0x18(%rbp)
jmp    1231 <main+0xc1>
mov    -0x1028(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
cmp    $0x2,%edi
jl     11a6 <main+0x36>
mov    0x8(%rsi),%rdi
lea    0xe6f(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x90000,%eax
jb     11b6 <main+0x46>
movl   $0xa,0xc(%rsp)
mov    $0x2,%r14d
jmp    11d2 <main+0x62>
cltq
imul   $0x38e38e39,%rax,%rax
mov    %rax,%rcx
sar    $0x21,%rcx
shr    $0x3f,%rax
lea    (%rcx,%rax,1),%r14d
add    $0x1,%r14d
lea    0xe2a(%rip),%rdi
lea    0xe30(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,0x10(%rsp)
lea    0xe21(%rip),%r12
lea    0x18(%rsp),%rbx
lea    0xe1c(%rip),%r13
jmp    1217 <main+0xa7>
nop
lea    -0x400(%r14),%eax
cmp    $0x400,%r14d
mov    %eax,%r14d
jle    12e9 <main+0x179>
lea    0x20(%rsp),%rdi
mov    $0x400,%esi
mov    $0x4,%edx
mov    0x10(%rsp),%rcx
call   1030 <fread@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    1200 <main+0x90>
mov    $0x1,%r15d
xchg   %ax,%ax
mov    0x1c(%rsp,%r15,4),%ebp
cmp    $0xee6b27ff,%ebp
ja     1280 <main+0x110>
cmp    $0x8,%edx
ja     1290 <main+0x120>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <sprintf@plt>
mov    0xc(%rsp),%edi
call   1090 <power10@plt>
mov    %eax,%ecx
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
mov    %rbx,%rdi
mov    %edx,%esi
jmp    12ad <main+0x13d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14d
jmp    12bd <main+0x14d>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%eax
shr    $0x9,%eax
imul   $0x44b83,%rax,%rax
shr    $0x27,%rax
imul   $0x3b9aca00,%eax,%eax
sub    %eax,%ebp
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    0xc(%rsp),%edx
add    $0xfffffff7,%edx
mov    %edx,0xc(%rsp)
cmp    $0x400,%r14d
mov    $0x400,%eax
cmovl  %r14d,%eax
cltq
cmp    %rax,%r15
jge    1200 <main+0x90>
add    $0x1,%r15
test   %edx,%edx
jg     1240 <main+0xd0>
jmp    1200 <main+0x90>
mov    0x10(%rsp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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 = [7 x i8] c"%%0%du\00"
@.str.4 = [5 x i8] c"%09u\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 i32
%9 = alloca [1024 x i32]
%10 = alloca i32*
%11 = alloca [8 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %2
store i32 10, i32* %8
%15 = load i32, i32* %8
%16 = sdiv i32 %15, 9
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
br label %39
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%23 = load i32, i32* %8
%24 = sdiv i32 %23, 9
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 1
br i1 %27, label %34, label %28
28: ; preds = %18
%29 = load i32, i32* %7
%30 = icmp sgt i32 %29, 65536
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31, %28, %18
store i32 10, i32* %8
%35 = load i32, i32* %8
%36 = sdiv i32 %35, 9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %38
38: ; preds = %34, %31
br label %39
39: ; preds = %38, %14
%40 = 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* %40, i32** %10
br label %41
41: ; preds = %102, %39
%42 = load i32, i32* %7
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %105
44: ; preds = %41
%45 = bitcast [1024 x i32]* %9 to i32**
%46 = load i32*, i32** %10
%47 = call i32 @fread(i32** %45, i32 1024, i32 4, i32* %46)
store i32 0, i32* %6
br label %48
48: ; preds = %99, %44
%49 = load i32, i32* %6
%50 = load i32, i32* %7
%51 = icmp sgt i32 %50, 1024
br i1 %51, label %52, label %53
52: ; preds = %48
br label %55
53: ; preds = %48
%54 = load i32, i32* %7
br label %55
55: ; preds = %53, %52
%56 = phi i32 [ 1024, %52 ], [ %54, %53 ]
%57 = icmp slt i32 %49, %56
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %8
%60 = icmp sgt i32 %59, 0
br label %61
61: ; preds = %58, %55
%62 = phi i1 [ false, %55 ], [ %60, %58 ]
br i1 %62, label %63, label %102
63: ; preds = %61
%64 = load i32, i32* %6
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [1024 x i32], [1024 x i32]* %9, i64 0, i64 %65
%67 = load i32, i32* %66
%68 = icmp ult i32 %67, -294967296
br i1 %68, label %69, label %95
69: ; preds = %63
%70 = load i32, i32* %8
%71 = icmp slt i32 %70, 9
br i1 %71, label %72, label %85
72: ; preds = %69
%73 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%74 = load i32, i32* %8
%75 = call i32 @sprintf(i8* %73, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %74)
%76 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%77 = load i32, i32* %6
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [1024 x i32], [1024 x i32]* %9, i64 0, i64 %78
%80 = load i32, i32* %79
%81 = load i32, i32* %8
%82 = call i32 @power10(i32 %81)
%83 = urem i32 %80, %82
%84 = call i32 @printf(i8* %76, i32 %83)
br label %92
85: ; preds = %69
%86 = load i32, i32* %6
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [1024 x i32], [1024 x i32]* %9, i64 0, i64 %87
%89 = load i32, i32* %88
%90 = urem i32 %89, 1000000000
%91 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %85, %72
%93 = load i32, i32* %8
%94 = sub nsw i32 %93, 9
store i32 %94, i32* %8
br label %98
95: ; preds = %63
%96 = load i32, i32* %7
%97 = add nsw i32 %96, 1
store i32 %97, i32* %7
br label %98
98: ; preds = %95, %92
br label %99
99: ; preds = %98
%100 = load i32, i32* %6
%101 = add nsw i32 %100, 1
store i32 %101, i32* %6
br label %48
102: ; preds = %61
%103 = load i32, i32* %7
%104 = sub nsw i32 %103, 1024
store i32 %104, i32* %7
br label %41
105: ; preds = %41
%106 = load i32*, i32** %10
%107 = call i32 @fclose(i32* %106)
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 = [7 x i8] c"%%0%du\00"
@.str.4 = [5 x i8] c"%09u\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i32]
%5 = alloca [8 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast [1024 x i32]* %4 to i8*
%8 = icmp slt i32 %0, 2
br i1 %8, label %15, label %9
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, 589823
br i1 %14, label %15, label %16
15: ; preds = %9, %2
store i32 10, i32* %3
br label %19
16: ; preds = %9
%17 = sdiv i32 %13, 9
%18 = add nsw i32 %17, 1
br label %19
19: ; preds = %16, %15
%20 = phi i32 [ 2, %15 ], [ %18, %16 ]
%21 = 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))
%22 = bitcast [1024 x i32]* %4 to i32**
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
br label %24
24: ; preds = %19, %62
%25 = phi i32 [ %20, %19 ], [ %64, %62 ]
%26 = call i32 @fread(i32** %22, i32 1024, i32 4, i32* %21)
%27 = load i32, i32* %3
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %62
29: ; preds = %24, %52
%30 = phi i32 [ %53, %52 ], [ %27, %24 ]
%31 = phi i64 [ %55, %52 ], [ 0, %24 ]
%32 = phi i32 [ %54, %52 ], [ %25, %24 ]
%33 = getelementptr inbounds [1024 x i32], [1024 x i32]* %4, i64 0, i64 %31
%34 = load i32, i32* %33
%35 = icmp ult i32 %34, -294967296
br i1 %35, label %36, label %50
36: ; preds = %29
%37 = icmp ult i32 %30, 9
br i1 %37, label %38, label %44
38: ; preds = %36
%39 = call i32 @sprintf(i8* %23, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%40 = load i32, i32* %3
%41 = call i32 @power10(i32 %40)
%42 = urem i32 %34, %41
%43 = call i32 @printf(i8* %23, i32 %42)
br label %47
44: ; preds = %36
%45 = urem i32 %34, 1000000000
%46 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %38
%48 = load i32, i32* %3
%49 = add nsw i32 %48, -9
store i32 %49, i32* %3
br label %52
50: ; preds = %29
%51 = add nsw i32 %32, 1
br label %52
52: ; preds = %47, %50
%53 = phi i32 [ %49, %47 ], [ %30, %50 ]
%54 = phi i32 [ %32, %47 ], [ %51, %50 ]
%55 = add nuw nsw i64 %31, 1
%56 = icmp slt i32 %54, 1024
%57 = select i1 %56, i32 %54, i32 1024
%58 = sext i32 %57 to i64
%59 = icmp slt i64 %55, %58
%60 = icmp sgt i32 %53, 0
%61 = select i1 %59, i1 %60, i1 false
br i1 %61, label %29, label %62
62: ; preds = %52, %24
%63 = phi i32 [ %25, %24 ], [ %54, %52 ]
%64 = add nsw i32 %63, -1024
%65 = icmp sgt i32 %63, 1024
br i1 %65, label %24, label %66
66: ; preds = %62
%67 = call i32 @fclose(i32* %21)
ret i32 0
}