#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*/ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int rand();
void s4(FILE *out, int count) {
  int i;
  int c = (unsigned char)rand();
  for (i = 0; i < count && !ferror(out); i++) {
    char s[4] = {c, c, c, c};
    fwrite(s, 1, 4, out);
    c += 1 + (rand() % 255);
  }
}


x86 assembly (clang, -O0):
<s4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x19(%rbp)
jge    1178 <s4+0x48>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1188 <s4+0x58>
jmp    11df <s4+0xaf>
mov    -0x14(%rbp),%eax
mov    %al,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x17(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x16(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x15(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fwrite@plt>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x1,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1153 <s4+0x23>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s4>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <rand@plt>
test   %ebp,%ebp
jle    11b1 <s4+0x81>
movzbl %al,%ebx
lea    0x4(%rsp),%r15
nop
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    11b1 <s4+0x81>
movzbl %bl,%eax
imul   $0x1010101,%eax,%eax
mov    %eax,0x4(%rsp)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r14,%rcx
call   1040 <fwrite@plt>
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
add    %eax,%ecx
add    %ecx,%ebx
add    $0x1,%ebx
add    $0xffffffff,%ebp
jne    1150 <s4+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @s4(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [4 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = call i32 (...) @rand()
%9 = trunc i32 %8 to i8
%10 = zext i8 %9 to i32
store i32 %10, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %43, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = call i32 @ferror(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br label %20
20: ; preds = %15, %11
%21 = phi i1 [ false, %11 ], [ %19, %15 ]
br i1 %21, label %22, label %46
22: ; preds = %20
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%24 = load i32, i32* %6
%25 = trunc i32 %24 to i8
store i8 %25, i8* %23
%26 = getelementptr inbounds i8, i8* %23, i64 1
%27 = load i32, i32* %6
%28 = trunc i32 %27 to i8
store i8 %28, i8* %26
%29 = getelementptr inbounds i8, i8* %26, i64 1
%30 = load i32, i32* %6
%31 = trunc i32 %30 to i8
store i8 %31, i8* %29
%32 = getelementptr inbounds i8, i8* %29, i64 1
%33 = load i32, i32* %6
%34 = trunc i32 %33 to i8
store i8 %34, i8* %32
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%36 = load i32*, i32** %3
%37 = call i32 @fwrite(i8* %35, i32 1, i32 4, i32* %36)
%38 = call i32 (...) @rand()
%39 = srem i32 %38, 255
%40 = add nsw i32 1, %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, %40
store i32 %42, i32* %6
br label %43
43: ; preds = %22
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %11
46: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @s4(i32* nocapture %0, i32 %1) {
%3 = alloca [4 x i8]
%4 = tail call i32 (...) @rand()
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %23
6: ; preds = %2
%7 = and i32 %4, 255
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
br label %9
9: ; preds = %6, %14
%10 = phi i32 [ %7, %6 ], [ %20, %14 ]
%11 = phi i32 [ 0, %6 ], [ %21, %14 ]
%12 = tail call i32 @ferror(i32* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = trunc i32 %10 to i8
%16 = call i32 @fwrite(i8* %8, i32 1, i32 4, i32* %0)
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 255
%19 = add i32 %10, 1
%20 = add i32 %19, %18
%21 = add nuw nsw i32 %11, 1
%22 = icmp eq i32 %21, %1
br i1 %22, label %23, label %9
23: ; preds = %9, %14, %2
ret void
}