#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*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int rand();
void sn(FILE *out, int count) {
  int i;
  for (i = 0; i < count && !ferror(out); i++) {
    int j;
    int runlen = rand() % 300 + 1;
    int c = (unsigned char)rand();
    for (j = 0; j < runlen; j++)
      fputc(c, out);
    if (c + (runlen & 3) == 19)
      fputs("Hello, world\n", out);
  }
}


x86 assembly (clang, -O0):
<sn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    117b <sn+0x3b>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    118b <sn+0x4b>
jmp    1211 <sn+0xd1>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x12c,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11da <sn+0x9a>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <sn+0x74>
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
and    $0x3,%ecx
add    %ecx,%eax
cmp    $0x13,%eax
jne    11fe <sn+0xbe>
mov    -0x8(%rbp),%rsi
lea    0xe07(%rip),%rdi
call   1040 <fputs@plt>
jmp    1203 <sn+0xc3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <sn+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
test   %esi,%esi
jle    1203 <sn+0xc3>
mov    %rdi,%rbx
xor    %r13d,%r13d
jmp    116f <sn+0x2f>
nop
add    $0x1,%r13d
cmp    0x4(%rsp),%r13d
je     1203 <sn+0xc3>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    1203 <sn+0xc3>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%r12d
movslq %eax,%r14
imul   $0x1b4e81b5,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x12c,%eax,%r15d
sub    %r15d,%r14d
neg    %r15d
xor    %eax,%eax
call   1060 <rand@plt>
movzbl %al,%ebp
test   %r14d,%r14d
js     11d0 <sn+0x90>
add    $0x1,%r14d
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0xffffffff,%r14d
jne    11c0 <sn+0x80>
lea    (%r12,%r15,1),%eax
add    $0x1,%eax
and    $0x3,%eax
add    %ebp,%eax
cmp    $0x13,%eax
jne    1160 <sn+0x20>
mov    $0xd,%esi
mov    $0x1,%edx
lea    0xe0a(%rip),%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
jmp    1160 <sn+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"Hello, world\0A\00"
define void @sn(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %29
4: ; preds = %2, %26
%5 = phi i32 [ %27, %26 ], [ 0, %2 ]
%6 = tail call i32 @ferror(i32* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %4
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 300
%11 = add nsw i32 %10, 1
%12 = tail call i32 (...) @rand()
%13 = and i32 %12, 255
%14 = icmp slt i32 %10, 0
br i1 %14, label %20, label %15
15: ; preds = %8, %15
%16 = phi i32 [ %18, %15 ], [ 0, %8 ]
%17 = tail call i32 @fputc(i32 %13, i32* %0)
%18 = add nuw nsw i32 %16, 1
%19 = icmp eq i32 %16, %10
br i1 %19, label %20, label %15
20: ; preds = %15, %8
%21 = and i32 %11, 3
%22 = add nuw nsw i32 %21, %13
%23 = icmp eq i32 %22, 19
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 13, i64 1, i32* %0)
br label %26
26: ; preds = %24, %20
%27 = add nuw nsw i32 %5, 1
%28 = icmp eq i32 %27, %1
br i1 %28, label %29, label %4
29: ; preds = %4, %26, %2
ret void
}