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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ rand();
int /*<<< orphan*/ write(int, int /*<<< orphan*/ *, int);
int main() {
  size_t i;
  size_t j;
  uint32_t b[BUFSIZ];
  for (i = 0, j = 0; i < (1024 * 1024 * 1024); i++, j++) {
    if (j >= BUFSIZ) {
      write(1, b, sizeof(uint32_t) * j);
      j = 0;
    }
    b[j] = rand();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x40000000,-0x10(%rbp)
40
jae    11e2 <main+0xc2>
mov    -0x18(%rbp),%rax
mov    0x2e5b(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jb     11b1 <main+0x91>
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%edx
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116c <main+0x4c>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2eae(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r14
mov    %r14,%rsp
mov    $0x3fffffff,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cltq
cmp    %rax,%rbx
jb     117b <main+0x5b>
shl    $0x2,%ebx
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,(%r14,%rbx,4)
sub    $0x1,%r12
jb     1195 <main+0x75>
add    $0x1,%rbx
mov    (%r15),%eax
jmp    1160 <main+0x40>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i32, i64 %7
store i64 %7, i64* %5
store i64 0, i64* %2
store i64 0, i64* %3
br label %10
10: ; preds = %27, %0
%11 = load i64, i64* %2
%12 = icmp ult i64 %11, 1073741824
br i1 %12, label %13, label %32
13: ; preds = %10
%14 = load i64, i64* %3
%15 = load i32, i32* @BUFSIZ
%16 = sext i32 %15 to i64
%17 = icmp uge i64 %14, %16
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i64, i64* %3
%20 = mul i64 4, %19
%21 = trunc i64 %20 to i32
%22 = call i32 @write(i32 1, i32* %9, i32 %21)
store i64 0, i64* %3
br label %23
23: ; preds = %18, %13
%24 = call i32 (...) @rand()
%25 = load i64, i64* %3
%26 = getelementptr inbounds i32, i32* %9, i64 %25
store i32 %24, i32* %26
br label %27
27: ; preds = %23
%28 = load i64, i64* %2
%29 = add i64 %28, 1
store i64 %29, i64* %2
%30 = load i64, i64* %3
%31 = add i64 %30, 1
store i64 %31, i64* %3
br label %10
32: ; preds = %10
store i32 0, i32* %1
%33 = load i8*, i8** %4
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
define i32 @main() {
%1 = load i32, i32* @BUFSIZ
%2 = zext i32 %1 to i64
%3 = alloca i32, i64 %2
br label %4
4: ; preds = %20, %0
%5 = phi i32 [ %1, %0 ], [ %22, %20 ]
%6 = phi i64 [ 0, %0 ], [ %18, %20 ]
%7 = phi i64 [ 0, %0 ], [ %21, %20 ]
%8 = sext i32 %5 to i64
%9 = icmp ult i64 %7, %8
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = trunc i64 %7 to i32
%12 = shl i32 %11, 2
%13 = call i32 @write(i32 1, i32* %3, i32 %12)
br label %14
14: ; preds = %10, %4
%15 = phi i64 [ 0, %10 ], [ %7, %4 ]
%16 = tail call i32 (...) @rand()
%17 = getelementptr inbounds i32, i32* %3, i64 %15
store i32 %16, i32* %17
%18 = add nuw nsw i64 %6, 1
%19 = icmp eq i64 %18, 1073741824
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = add nuw i64 %15, 1
%22 = load i32, i32* @BUFSIZ
br label %4
23: ; preds = %14
ret i32 0
}