#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 */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(int /*<<< orphan*/ **);
int /*<<< orphan*/ gzclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *gzopen(char *, char *);
int /*<<< orphan*/ **malloc(int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ split(int, int /*<<< orphan*/ **);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int sscanf(char *, char *, int *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syntax();
int main(int argc, char *argv[]) {
  int n;
  if (argc != 3)
    syntax();
  int num_split;
  n = sscanf(argv[1], "%d", &num_split);
  if (n != 1)
    syntax();
  char *prefix = argv[2];
  gzFile **files = malloc(sizeof(*files) * num_split);
  for (n = 0; n < num_split; n++) {
    char filename[1024];
    sprintf(filename, "%s.%04d.gz", prefix, n);
    files[n] = gzopen(filename, "w");
    if (files[n] == NULL) {
      printf("%s: %s\n", filename, strerror(errno));
      return 1;
    }
  }
  split(num_split, files);
  for (n = 0; n < num_split; n++) {
    gzclose(files[n]);
  }
  free(files);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ca <main+0x2a>
mov    $0x0,%al
call   1090 <syntax@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe27(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1080 <sscanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     11f6 <main+0x56>
mov    $0x0,%al
call   1090 <syntax@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12c8 <main+0x128>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xdc6(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x430(%rbp),%rdi
lea    0xdbe(%rip),%rsi
call   10a0 <gzopen@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    12b5 <main+0x115>
lea    -0x430(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x438(%rbp),%rsi
mov    %rax,%rdx
lea    0xd6c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1316 <main+0x176>
jmp    12ba <main+0x11a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121c <main+0x7c>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <split@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1306 <main+0x166>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <gzclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12db <main+0x13b>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     11c0 <main+0x20>
xor    %eax,%eax
call   1090 <syntax@plt>
mov    0x8(%rbx),%rdi
lea    0xe35(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     11e1 <main+0x41>
xor    %eax,%eax
call   1090 <syntax@plt>
mov    0x10(%rbx),%r14
mov    0xc(%rsp),%r12d
lea    0x0(,%r12,8),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
test   %r12d,%r12d
jle    1246 <main+0xa6>
xor    %ebx,%ebx
lea    0x10(%rsp),%r13
lea    0xe01(%rip),%rbp
nopl   (%rax)
mov    %r13,%rdi
lea    0xde9(%rip),%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
call   10b0 <sprintf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10a0 <gzopen@plt>
mov    %rax,(%r15,%rbx,8)
test   %rax,%rax
je     1283 <main+0xe3>
add    $0x1,%rbx
movslq 0xc(%rsp),%r12
cmp    %r12,%rbx
jl     1210 <main+0x70>
mov    %r12d,%edi
mov    %r15,%rsi
call   1060 <split@plt>
cmpl   $0x0,0xc(%rsp)
jle    1277 <main+0xd7>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
call   1030 <gzclose@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1260 <main+0xc0>
mov    %r15,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    12aa <main+0x10a>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd78(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c"%s.%04d.gz\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32**
%10 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (...) @syntax()
br label %15
15: ; preds = %13, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 (...) @syntax()
br label %24
24: ; preds = %22, %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %8
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = mul i64 8, %29
%31 = trunc i64 %30 to i32
%32 = call i32** @malloc(i32 %31)
store i32** %32, i32*** %9
store i32 0, i32* %6
br label %33
33: ; preds = %60, %24
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %63
37: ; preds = %33
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%39 = load i8*, i8** %8
%40 = load i32, i32* %6
%41 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %39, i32 %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%43 = call i32* @gzopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32**, i32*** %9
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32*, i32** %44, i64 %46
store i32* %43, i32** %47
%48 = load i32**, i32*** %9
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32*, i32** %48, i64 %50
%52 = load i32*, i32** %51
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %59
54: ; preds = %37
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %55, i8* %57)
store i32 1, i32* %3
br label %84
59: ; preds = %37
br label %60
60: ; preds = %59
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %33
63: ; preds = %33
%64 = load i32, i32* %7
%65 = load i32**, i32*** %9
%66 = call i32 @split(i32 %64, i32** %65)
store i32 0, i32* %6
br label %67
67: ; preds = %78, %63
%68 = load i32, i32* %6
%69 = load i32, i32* %7
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %81
71: ; preds = %67
%72 = load i32**, i32*** %9
%73 = load i32, i32* %6
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32*, i32** %72, i64 %74
%76 = load i32*, i32** %75
%77 = call i32 @gzclose(i32* %76)
br label %78
78: ; preds = %71
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %67
81: ; preds = %67
%82 = load i32**, i32*** %9
%83 = call i32 @free(i32** %82)
store i32 0, i32* %3
br label %84
84: ; preds = %81, %54
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c"%s.%04d.gz\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @syntax()
br label %8
8: ; preds = %6, %2
%9 = bitcast i32* %3 to i8*
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%13 = icmp eq i32 %12, 1
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = call i32 (...) @syntax()
br label %16
16: ; preds = %14, %8
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = load i32, i32* %3
%20 = shl i32 %19, 3
%21 = call i32** @malloc(i32 %20)
%22 = icmp sgt i32 %19, 0
br i1 %22, label %23, label %41
23: ; preds = %16
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %25
25: ; preds = %23, %36
%26 = phi i64 [ 0, %23 ], [ %37, %36 ]
%27 = trunc i64 %26 to i32
%28 = call i32 @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %27)
%29 = call i32* @gzopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = getelementptr inbounds i32*, i32** %21, i64 %26
store i32* %29, i32** %30
%31 = icmp eq i32* %29, null
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* %34)
br label %57
36: ; preds = %25
%37 = add nuw nsw i64 %26, 1
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %37, %39
br i1 %40, label %25, label %41
41: ; preds = %36, %16
%42 = phi i32 [ %19, %16 ], [ %38, %36 ]
%43 = call i32 @split(i32 %42, i32** %21)
%44 = load i32, i32* %3
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %41, %46
%47 = phi i64 [ %51, %46 ], [ 0, %41 ]
%48 = getelementptr inbounds i32*, i32** %21, i64 %47
%49 = load i32*, i32** %48
%50 = call i32 @gzclose(i32* %49)
%51 = add nuw nsw i64 %47, 1
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %51, %53
br i1 %54, label %46, label %55
55: ; preds = %46, %41
%56 = call i32 @free(i32** %21)
br label %57
57: ; preds = %32, %55
%58 = phi i32 [ 0, %55 ], [ 1, %32 ]
ret i32 %58
}