#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*/ fprintf(int /*<<< orphan*/ *, char *, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main() {
  srand(time(0));
  FILE *out;
  out = fopen("Dane.txt", "w");
  int i;
  for (i = 0; i < 1000; i++)
    fprintf(out, "%d\n", rand() % 256);
  fclose(out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe7c(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    11dd <main+0x7d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    -0x20(%rbp),%rdi
mov    $0x100,%ecx
cltd
idiv   %ecx
lea    0xe41(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119b <main+0x3b>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe87(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    $0x3e8,%ebp
lea    0xe77(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1080 <rand@plt>
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffff00,%ecx
sub    %ecx,%eax
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
add    $0xffffffff,%ebp
jne    11a0 <main+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Dane.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @time(i32 0)
%5 = call i32 @srand(i32 %4)
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
store i32 0, i32* %3
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 1000
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 256
%14 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %10
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %7
18: ; preds = %7
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [9 x i8] c"Dane.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32 @time(i32 0)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %9, %4 ]
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 256
%8 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = add nuw nsw i32 %5, 1
%10 = icmp eq i32 %9, 1000
br i1 %10, label %11, label %4
11: ; preds = %4
%12 = tail call i32 @fclose(i32* %3)
ret i32 0
}