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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fatal_error(char *, ...);
int /*<<< orphan*/ multiple_writers(char *, int, int, int);
int /*<<< orphan*/ setup();
int main(int argc, char *argv[]) {
  if (argc != 5)
    fatal_error("Usage: %s <file_path> <n_lines> <n_processes> <n_threads>\n",
                argv[0]);
  int n_lines = atoi(argv[2]);
  int n_processes = atoi(argv[3]);
  int n_threads = atoi(argv[4]);
  if (n_lines <= 0)
    fatal_error("wrong number of lines\n");
  if (n_processes <= 0)
    fatal_error("wrong number of processes\n");
  if (n_threads <= 0)
    fatal_error("wrong number of threads\n");
  setup();
  multiple_writers(argv[1], n_lines, n_processes, n_threads);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1175 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <fatal_error@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11bd <main+0x7d>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <fatal_error@plt>
cmpl   $0x0,-0x18(%rbp)
jg     11d5 <main+0x95>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <fatal_error@plt>
cmpl   $0x0,-0x1c(%rbp)
jg     11ed <main+0xad>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <fatal_error@plt>
mov    $0x0,%al
call   1060 <setup@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <multiple_writers@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x5,%edi
je     1160 <main+0x20>
mov    (%rbx),%rsi
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1040 <fatal_error@plt>
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%r15d
mov    0x20(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
test   %r14d,%r14d
jle    11b6 <main+0x76>
test   %r15d,%r15d
jle    11c9 <main+0x89>
test   %ebp,%ebp
jle    11db <main+0x9b>
xor    %eax,%eax
call   1060 <setup@plt>
mov    0x8(%rbx),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
call   1030 <multiple_writers@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1040 <fatal_error@plt>
test   %r15d,%r15d
jg     118d <main+0x4d>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1040 <fatal_error@plt>
test   %ebp,%ebp
jg     1191 <main+0x51>
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1040 <fatal_error@plt>
jmp    1191 <main+0x51>

LLVM IR (-O0):
@.str = [59 x i8] c"Usage: %s <file_path> <n_lines> <n_processes> <n_threads>\0A\00"
@.str.1 = [23 x i8] c"wrong number of lines\0A\00"
@.str.2 = [27 x i8] c"wrong number of processes\0A\00"
@.str.3 = [25 x i8] c"wrong number of threads\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 5
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @fatal_error(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %11, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 3
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %7
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 4
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %8
%29 = load i32, i32* %6
%30 = icmp sle i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %16
%32 = call i32 (i8*, ...) @fatal_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %16
%34 = load i32, i32* %7
%35 = icmp sle i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 (i8*, ...) @fatal_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
%39 = load i32, i32* %8
%40 = icmp sle i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 (i8*, ...) @fatal_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = call i32 (...) @setup()
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = call i32 @multiple_writers(i8* %47, i32 %48, i32 %49, i32 %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [59 x i8] c"Usage: %s <file_path> <n_lines> <n_processes> <n_threads>\0A\00"
@.str.1 = [23 x i8] c"wrong number of lines\0A\00"
@.str.2 = [27 x i8] c"wrong number of processes\0A\00"
@.str.3 = [25 x i8] c"wrong number of threads\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @fatal_error(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 4
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = icmp slt i32 %10, 1
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = tail call i32 (i8*, ...) @fatal_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %7
%21 = icmp slt i32 %13, 1
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 (i8*, ...) @fatal_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
%25 = icmp slt i32 %16, 1
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = tail call i32 (i8*, ...) @fatal_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %24
%29 = tail call i32 (...) @setup()
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = tail call i32 @multiple_writers(i8* %31, i32 %10, i32 %13, i32 %16)
ret i32 0
}