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

/* Variables and functions */
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gzputs(int /*<<< orphan*/ *, char *);
char *malloc(int);
int random();
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
void split(int num_split, gzFile *files[]) {
  int file = -1;
  char *buffer, *r;
  buffer = malloc((5 * 1024 * 1024) * sizeof(*buffer));
  while (1) {
    r = fgets(buffer, (5 * 1024 * 1024), stdin);
    if (r == NULL)
      return;
    if (!strcmp(buffer, "  <page>\n")) {
      file = random() % num_split;
    }
    if (file == -1) {
      int n;
      for (n = 0; n < num_split; n++)
        gzputs(files[n], buffer);
    } else {
      gzputs(files[file], buffer);
    }
    if (!strcmp(buffer, "  </page>\n")) {
      file = -1;
    }
  }
  free(buffer);
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    $0x500000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    $0x500000,%esi
call   1030 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a0 <split+0x50>
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x20(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11c7 <split+0x77>
mov    $0x0,%al
call   1060 <random@plt>
cltd
idivl  -0x4(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    120c <split+0xbc>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1207 <split+0xb7>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <gzputs@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d8 <split+0x88>
jmp    1221 <split+0xd1>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <gzputs@plt>
mov    -0x20(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1241 <split+0xf1>
movl   $0xffffffff,-0x14(%rbp)
jmp    1174 <split+0x24>

x86 assembly (clang, -O2):
<split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,0x4(%rsp)
mov    $0x500000,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x500000,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     123a <split+0xea>
mov    0x4(%rsp),%r15d
mov    $0xffffffff,%r13d
jmp    11e2 <split+0x92>
nopl   0x0(%rax,%rax,1)
movslq %r12d,%rax
mov    (%r14,%rax,8),%rdi
mov    %rbp,%rsi
call   1050 <gzputs@plt>
mov    %rbp,%rdi
lea    0xe51(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x1,%eax
sbb    %r13d,%r13d
or     %r12d,%r13d
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x500000,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     123a <split+0xea>
mov    %rbp,%rdi
lea    0xe14(%rip),%rsi
call   1040 <strcmp@plt>
mov    %r13d,%r12d
test   %eax,%eax
je     1200 <split+0xb0>
cmp    $0xffffffff,%r12d
jne    11a0 <split+0x50>
jmp    1215 <split+0xc5>
xor    %eax,%eax
call   1060 <random@plt>
cltd
idivl  0x4(%rsp)
mov    %edx,%r12d
cmp    $0xffffffff,%r12d
jne    11a0 <split+0x50>
cmpl   $0x0,0x4(%rsp)
jle    11af <split+0x5f>
xor    %ebx,%ebx
xchg   %ax,%ax
mov    (%r14,%rbx,8),%rdi
mov    %rbp,%rsi
call   1050 <gzputs@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1220 <split+0xd0>
jmp    11af <split+0x5f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [10 x i8] c" <page>\0A\00"
@.str.1 = [11 x i8] c" </page>\0A\00"
define void @split(i32 %0, i32** %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %3
store i32** %1, i32*** %4
store i32 -1, i32* %5
%9 = call i8* @malloc(i32 5242880)
store i8* %9, i8** %6
br label %10
10: ; preds = %2, %58
%11 = load i8*, i8** %6
%12 = load i32, i32* @stdin
%13 = call i8* @fgets(i8* %11, i32 5242880, i32 %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %10
ret void
17: ; preds = %10
%18 = load i8*, i8** %6
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = call i32 (...) @random()
%23 = load i32, i32* %3
%24 = srem i32 %22, %23
store i32 %24, i32* %5
br label %25
25: ; preds = %21, %17
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %45
28: ; preds = %25
store i32 0, i32* %8
br label %29
29: ; preds = %41, %28
%30 = load i32, i32* %8
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = load i32**, i32*** %4
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32*, i32** %34, i64 %36
%38 = load i32*, i32** %37
%39 = load i8*, i8** %6
%40 = call i32 @gzputs(i32* %38, i8* %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %29
44: ; preds = %29
br label %53
45: ; preds = %25
%46 = load i32**, i32*** %4
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32*, i32** %46, i64 %48
%50 = load i32*, i32** %49
%51 = load i8*, i8** %6
%52 = call i32 @gzputs(i32* %50, i8* %51)
br label %53
53: ; preds = %45, %44
%54 = load i8*, i8** %6
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %53
store i32 -1, i32* %5
br label %58
58: ; preds = %57, %53
br label %10
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [10 x i8] c" <page>\0A\00"
@.str.1 = [11 x i8] c" </page>\0A\00"
define void @split(i32 %0, i32** nocapture %1) {
%3 = tail call dereferenceable_or_null(5242880) i8* @malloc(i32 5242880)
%4 = load i32, i32* @stdin
%5 = tail call i8* @fgets(i8* %3, i32 5242880, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 0
%9 = zext i32 %0 to i64
br label %11
10: ; preds = %34, %2
ret void
11: ; preds = %7, %34
%12 = phi i32 [ -1, %7 ], [ %37, %34 ]
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %3, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = tail call i32 (...) @random()
%17 = srem i32 %16, %0
br label %18
18: ; preds = %15, %11
%19 = phi i32 [ %12, %11 ], [ %17, %15 ]
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %29
21: ; preds = %18
br i1 %8, label %22, label %34
22: ; preds = %21, %22
%23 = phi i64 [ %27, %22 ], [ 0, %21 ]
%24 = getelementptr inbounds i32*, i32** %1, i64 %23
%25 = load i32*, i32** %24
%26 = tail call i32 @gzputs(i32* %25, i8* %3)
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %34, label %22
29: ; preds = %18
%30 = sext i32 %19 to i64
%31 = getelementptr inbounds i32*, i32** %1, i64 %30
%32 = load i32*, i32** %31
%33 = tail call i32 @gzputs(i32* %32, i8* %3)
br label %34
34: ; preds = %22, %21, %29
%35 = tail call i32 @strcmp(i8* dereferenceable(1) %3, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i32 -1, i32 %19
%38 = load i32, i32* @stdin
%39 = tail call i8* @fgets(i8* %3, i32 5242880, i32 %38)
%40 = icmp eq i8* %39, null
br i1 %40, label %10, label %11
}