#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 EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(char);
int main(void) {
  int c;
  int counter = 0;
  FILE *urandom;
  urandom = fopen("/dev/urandom", "r");
  while ((c = fgetc(urandom)) != EOF) {
    printf("%d", c % 10);
    counter += 1;
    if (counter % 80 == 0)
      putchar('\n');
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xea3(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%eax
je     11cd <main+0x8d>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x50,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c8 <main+0x88>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    116d <main+0x2d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e78(%rip),%rcx
cmp    (%rcx),%eax
jne    1185 <main+0x45>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ebp
mov    $0x1,%ebx
mov    $0xcccccccd,%r13d
lea    0xe73(%rip),%r14
jmp    11b9 <main+0x79>
xchg   %ax,%ax
mov    %r12,%rdi
call   1050 <fgetc@plt>
add    $0xffffffff,%ebp
add    $0x1,%ebx
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%eax
je     1174 <main+0x34>
mov    %ebx,%ecx
imul   %r13,%rcx
shr    $0x26,%rcx
lea    (%rcx,%rcx,4),%r15d
shl    $0x4,%r15d
movslq %eax,%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    %ebp,%r15d
jne    11a0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11a0 <main+0x60>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
br label %6
6: ; preds = %22, %0
%7 = load i32*, i32** %4
%8 = call i32 @fgetc(i32* %7)
store i32 %8, i32* %2
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %6
%12 = load i32, i32* %2
%13 = srem i32 %12, 10
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = srem i32 %17, 80
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 @putchar(i8 signext 10)
br label %22
22: ; preds = %20, %11
br label %6
23: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @fgetc(i32* %1)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %19, label %5
5: ; preds = %0, %15
%6 = phi i32 [ %16, %15 ], [ %2, %0 ]
%7 = phi i32 [ %10, %15 ], [ 0, %0 ]
%8 = srem i32 %6, 10
%9 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = add nuw nsw i32 %7, 1
%11 = urem i32 %10, 80
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = tail call i32 @putchar(i8 signext 10)
br label %15
15: ; preds = %13, %5
%16 = tail call i32 @fgetc(i32* %1)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %5
19: ; preds = %15, %0
ret i32 0
}