#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 pid_t;

/* Variables and functions */
scalar_t__ WEXITSTATUS(int);
int atoi(char *);
int /*<<< orphan*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int time(int /*<<< orphan*/ *);
int wait(int *);
int main(int argc, char *argv[]) {
  if (argc < 4) {
    return 1;
  }
  char startbuff[50], endbuff[50], buf[4 * 3];
  pid_t pid;
  int start = atoi(argv[1]) - 1, end = atoi(argv[2]),
      process_count = atoi(argv[3]), tasks = end - start,
      tasks_per_process = (tasks / process_count),
      tasks_additional = tasks - (tasks_per_process * process_count),
      pierwszych = 0, i, status, fd, sub_start, sub_end, start_time, end_time;
  start_time = time(NULL);
  for (i = 0; i < process_count; i++) {
    if (fork() == 0) {
      sub_start = start + (i * tasks_per_process) + 1;
      sub_end = start + (i + 1) * tasks_per_process;
      if (i + 1 == process_count) {
        sub_end += tasks_additional;
      }
      sprintf(startbuff, "%d", sub_start);
      sprintf(endbuff, "%d", sub_end);
      execl("./pierwsza_zad1", "pierwsza_zad1", startbuff, endbuff, NULL);
      perror("error");
    }
  }
  for (i = 0; i < process_count; i++) {
    pid = wait(&status);
    printf("process stopped [pid=%d]\n", pid);
    pierwszych += WEXITSTATUS(status);
  }
  end_time = time(NULL);
  printf("pierwszych = %d\n", pierwszych);
  printf("czas wykonywania = %d\n", end_time - start_time);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11bf <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    140d <main+0x27d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
sub    $0x1,%eax
mov    %eax,-0xa4(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0xa8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0xac(%rbp)
mov    -0xa8(%rbp),%eax
sub    -0xa4(%rbp),%eax
mov    %eax,-0xb0(%rbp)
mov    -0xb0(%rbp),%eax
cltd
idivl  -0xac(%rbp)
mov    %eax,-0xb4(%rbp)
mov    -0xb0(%rbp),%eax
mov    -0xb4(%rbp),%ecx
imul   -0xac(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0xb8(%rbp)
movl   $0x0,-0xbc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0xd4(%rbp)
movl   $0x0,-0xc0(%rbp)
mov    -0xc0(%rbp),%eax
cmp    -0xac(%rbp),%eax
jge    135b <main+0x1cb>
mov    $0x0,%al
call   10b0 <fork@plt>
cmp    $0x0,%rax
jne    1342 <main+0x1b2>
mov    -0xa4(%rbp),%eax
mov    -0xc0(%rbp),%ecx
imul   -0xb4(%rbp),%ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0xcc(%rbp)
mov    -0xa4(%rbp),%eax
mov    -0xc0(%rbp),%ecx
add    $0x1,%ecx
imul   -0xb4(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0xd0(%rbp)
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
cmp    -0xac(%rbp),%eax
jne    12e4 <main+0x154>
mov    -0xb8(%rbp),%eax
add    -0xd0(%rbp),%eax
mov    %eax,-0xd0(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0xcc(%rbp),%edx
lea    0xd0b(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x90(%rbp),%rdi
mov    -0xd0(%rbp),%edx
lea    0xcf2(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x50(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xcde(%rip),%rdi
lea    0xcd9(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <execl@plt>
lea    0xcd6(%rip),%rdi
call   1060 <perror@plt>
jmp    1347 <main+0x1b7>
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
jmp    125e <main+0xce>
movl   $0x0,-0xc0(%rbp)
mov    -0xc0(%rbp),%eax
cmp    -0xac(%rbp),%eax
jge    13cd <main+0x23d>
lea    -0xc4(%rbp),%rdi
call   10a0 <wait@plt>
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%esi
lea    0xc83(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc4(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %rax,%rcx
movslq -0xbc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xbc(%rbp)
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
jmp    1365 <main+0x1d5>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0xd8(%rbp)
mov    -0xbc(%rbp),%esi
lea    0xc4a(%rip),%rdi
call   1030 <printf@plt>
mov    -0xd8(%rbp),%esi
sub    -0xd4(%rbp),%esi
lea    0xc43(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
cmp    $0x4,%edi
jl     131e <main+0x18e>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rax,0x18(%rsp)
lea    -0x1(%rax),%r14d
mov    0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
mov    0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    %r14d,0xc(%rsp)
sub    %r14d,%ebx
mov    %ebx,%eax
cltd
idiv   %ebp
mov    %edx,0x10(%rsp)
mov    %eax,0x8(%rsp)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
mov    $0x0,%ebx
test   %ebp,%ebp
jle    12e2 <main+0x152>
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     122a <main+0x9a>
add    $0x1,%r15d
cmp    %ebp,%r15d
jne    1210 <main+0x80>
jmp    12ab <main+0x11b>
mov    %r15d,%edx
mov    0x8(%rsp),%ecx
imul   %ecx,%edx
add    0x18(%rsp),%edx
add    $0x1,%r15d
mov    %r15d,%eax
imul   %ecx,%eax
add    0xc(%rsp),%eax
cmp    %ebp,%r15d
mov    $0x0,%ebx
cmove  0x10(%rsp),%ebx
add    %eax,%ebx
lea    0x60(%rsp),%r13
mov    %r13,%rdi
lea    0xd9c(%rip),%r12
mov    %r12,%rsi
call   1080 <sprintf@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1080 <sprintf@plt>
lea    0xd7e(%rip),%rdi
lea    0xd79(%rip),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1090 <execl@plt>
lea    0xd72(%rip),%rdi
call   1060 <perror@plt>
jmp    1220 <main+0x90>
xor    %ebx,%ebx
test   %ebp,%ebp
jle    12e2 <main+0x152>
lea    0x14(%rsp),%r14
lea    0xd5c(%rip),%r15
nopl   (%rax)
mov    %r14,%rdi
call   10a0 <wait@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0x14(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    12c0 <main+0x130>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ebp
lea    0xd41(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
sub    0x4(%rsp),%ebp
lea    0xd40(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x98,%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 = [16 x i8] c"./pierwsza_zad1\00"
@.str.2 = [14 x i8] c"pierwsza_zad1\00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [26 x i8] c"process stopped [pid=%d]\0A\00"
@.str.5 = [17 x i8] c"pierwszych = %d\0A\00"
@.str.6 = [23 x i8] c"czas wykonywania = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50 x i8]
%7 = alloca [50 x i8]
%8 = alloca [12 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %27
26: ; preds = %2
store i32 1, i32* %3
br label %122
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = sub nsw i32 %31, 1
store i32 %32, i32* %10
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %11
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %12
%41 = load i32, i32* %11
%42 = load i32, i32* %10
%43 = sub nsw i32 %41, %42
store i32 %43, i32* %13
%44 = load i32, i32* %13
%45 = load i32, i32* %12
%46 = sdiv i32 %44, %45
store i32 %46, i32* %14
%47 = load i32, i32* %13
%48 = load i32, i32* %14
%49 = load i32, i32* %12
%50 = mul nsw i32 %48, %49
%51 = sub nsw i32 %47, %50
store i32 %51, i32* %15
store i32 0, i32* %16
%52 = call i32 @time(i32* null)
store i32 %52, i32* %22
store i32 0, i32* %17
br label %53
53: ; preds = %93, %27
%54 = load i32, i32* %17
%55 = load i32, i32* %12
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %96
57: ; preds = %53
%58 = call i64 (...) @fork()
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %92
60: ; preds = %57
%61 = load i32, i32* %10
%62 = load i32, i32* %17
%63 = load i32, i32* %14
%64 = mul nsw i32 %62, %63
%65 = add nsw i32 %61, %64
%66 = add nsw i32 %65, 1
store i32 %66, i32* %20
%67 = load i32, i32* %10
%68 = load i32, i32* %17
%69 = add nsw i32 %68, 1
%70 = load i32, i32* %14
%71 = mul nsw i32 %69, %70
%72 = add nsw i32 %67, %71
store i32 %72, i32* %21
%73 = load i32, i32* %17
%74 = add nsw i32 %73, 1
%75 = load i32, i32* %12
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %81
77: ; preds = %60
%78 = load i32, i32* %15
%79 = load i32, i32* %21
%80 = add nsw i32 %79, %78
store i32 %80, i32* %21
br label %81
81: ; preds = %77, %60
%82 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%83 = load i32, i32* %20
%84 = call i32 @sprintf(i8* %82, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %83)
%85 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%86 = load i32, i32* %21
%87 = call i32 @sprintf(i8* %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %86)
%88 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%89 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%90 = call i32 @execl(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %88, i8* %89, i32* null)
%91 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %92
92: ; preds = %81, %57
br label %93
93: ; preds = %92
%94 = load i32, i32* %17
%95 = add nsw i32 %94, 1
store i32 %95, i32* %17
br label %53
96: ; preds = %53
store i32 0, i32* %17
br label %97
97: ; preds = %111, %96
%98 = load i32, i32* %17
%99 = load i32, i32* %12
%100 = icmp slt i32 %98, %99
br i1 %100, label %101, label %114
101: ; preds = %97
%102 = call i32 @wait(i32* %18)
store i32 %102, i32* %9
%103 = load i32, i32* %9
%104 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %103)
%105 = load i32, i32* %18
%106 = call i64 @WEXITSTATUS(i32 %105)
%107 = load i32, i32* %16
%108 = sext i32 %107 to i64
%109 = add nsw i64 %108, %106
%110 = trunc i64 %109 to i32
store i32 %110, i32* %16
br label %111
111: ; preds = %101
%112 = load i32, i32* %17
%113 = add nsw i32 %112, 1
store i32 %113, i32* %17
br label %97
114: ; preds = %97
%115 = call i32 @time(i32* null)
store i32 %115, i32* %23
%116 = load i32, i32* %16
%117 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %116)
%118 = load i32, i32* %23
%119 = load i32, i32* %22
%120 = sub nsw i32 %118, %119
%121 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %120)
store i32 0, i32* %3
br label %122
122: ; preds = %114, %26
%123 = load i32, i32* %3
ret i32 %123
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [16 x i8] c"./pierwsza_zad1\00"
@.str.2 = [14 x i8] c"pierwsza_zad1\00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [26 x i8] c"process stopped [pid=%d]\0A\00"
@.str.5 = [17 x i8] c"pierwszych = %d\0A\00"
@.str.6 = [23 x i8] c"czas wykonywania = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = alloca [50 x i8]
%5 = alloca i32
%6 = icmp slt i32 %0, 4
br i1 %6, label %67, label %7
7: ; preds = %2
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = add nsw i32 %12, -1
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = sub nsw i32 %16, %13
%21 = sdiv i32 %20, %19
%22 = mul nsw i32 %21, %19
%23 = srem i32 %20, %19
%24 = bitcast i32* %5 to i8*
%25 = tail call i32 @time(i32* null)
%26 = icmp sgt i32 %19, 0
br i1 %26, label %28, label %61
27: ; preds = %47
br i1 %26, label %50, label %61
28: ; preds = %7, %47
%29 = phi i32 [ %48, %47 ], [ 0, %7 ]
%30 = call i64 (...) @fork()
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = add nuw nsw i32 %29, 1
br label %47
34: ; preds = %28
%35 = mul nsw i32 %29, %21
%36 = add i32 %35, %12
%37 = add nuw nsw i32 %29, 1
%38 = mul nsw i32 %37, %21
%39 = add nsw i32 %38, %13
%40 = icmp eq i32 %37, %19
%41 = select i1 %40, i32 %23, i32 0
%42 = add nsw i32 %39, %41
%43 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %36)
%44 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %42)
%45 = call i32 @execl(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %9, i32* null)
%46 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %32, %34
%48 = phi i32 [ %33, %32 ], [ %37, %34 ]
%49 = icmp eq i32 %48, %19
br i1 %49, label %27, label %28
50: ; preds = %27, %50
%51 = phi i32 [ %58, %50 ], [ 0, %27 ]
%52 = phi i32 [ %59, %50 ], [ 0, %27 ]
%53 = call i32 @wait(i32* %5)
%54 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %5
%56 = call i64 @WEXITSTATUS(i32 %55)
%57 = trunc i64 %56 to i32
%58 = add i32 %51, %57
%59 = add nuw nsw i32 %52, 1
%60 = icmp eq i32 %59, %19
br i1 %60, label %61, label %50
61: ; preds = %50, %7, %27
%62 = phi i32 [ 0, %27 ], [ 0, %7 ], [ %58, %50 ]
%63 = call i32 @time(i32* null)
%64 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %62)
%65 = sub nsw i32 %63, %25
%66 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %2, %61
%68 = phi i32 [ 0, %61 ], [ 1, %2 ]
ret i32 %68
}