#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ generate_dna(char *, char *, int, int, int);
char *generate_random_dna(int);
int /*<<< orphan*/ gethostname(char *, int);
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
void do_work(int workers, int files, int bytes, int mult) {
  char *dna = generate_random_dna(bytes);
  char filename[80];
  int hl;
  int i;
  gethostname(filename, 79);
  strcat(filename, "-");
  if (workers == 1)
    generate_dna(filename, dna, files, bytes, mult);
  else {
    hl = strlen(filename);
    for (i = 0; i < workers; i++)
      if (fork() == 0) {
        sprintf(filename + hl, "%d-", getpid());
        generate_dna(filename, dna, files, bytes, mult);
        exit(0);
      }
    while (workers--)
      wait(NULL);
  }
}


x86 assembly (clang, -O0):
<do_work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <generate_random_dna@plt>
mov    %rax,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x4f,%esi
call   1080 <gethostname@plt>
lea    -0x70(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1070 <strcat@plt>
cmpl   $0x1,-0x4(%rbp)
jne    1207 <do_work+0x67>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   1060 <generate_dna@plt>
jmp    12bc <do_work+0x11c>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1290 <do_work+0xf0>
mov    $0x0,%al
call   10c0 <fork@plt>
cmp    $0x0,%rax
jne    127d <do_work+0xdd>
lea    -0x70(%rbp),%rax
movslq -0x74(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x80(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%edx
lea    0xda6(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   1060 <generate_dna@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    1282 <do_work+0xe2>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    121a <do_work+0x7a>
jmp    1295 <do_work+0xf5>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     12b7 <do_work+0x117>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <wait@plt>
jmp    1295 <do_work+0xf5>
jmp    12bc <do_work+0x11c>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_work>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %ecx,%ebx
mov    %edx,%r13d
mov    %esi,%r15d
mov    %edi,%r14d
mov    %edx,%edi
call   1050 <generate_random_dna@plt>
mov    %rax,%r12
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x4f,%esi
call   1080 <gethostname@plt>
lea    0xe26(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcat@plt>
cmp    $0x1,%r14d
jne    1202 <do_work+0x62>
lea    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r13d,%ecx
mov    %ebx,%r8d
call   1060 <generate_dna@plt>
jmp    124d <do_work+0xad>
mov    %ebx,0xc(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
test   %r14d,%r14d
jle    1231 <do_work+0x91>
mov    %eax,%ebp
mov    %r14d,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
je     125c <do_work+0xbc>
add    $0xffffffff,%ebx
jne    1220 <do_work+0x80>
test   %r14d,%r14d
je     124d <do_work+0xad>
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
call   10b0 <wait@plt>
add    $0xffffffff,%r14d
jne    1240 <do_work+0xa0>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rbx
add    $0x10,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xd8b(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
lea    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r13d,%ecx
mov    0xc(%rsp),%r8d
call   1060 <generate_dna@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [4 x i8] c"%d-\00"
define void @do_work(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [80 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %7
%14 = call i8* @generate_random_dna(i32 %13)
store i8* %14, i8** %9
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%16 = call i32 @gethostname(i8* %15, i32 79)
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %28
21: ; preds = %4
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%23 = load i8*, i8** %9
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = call i32 @generate_dna(i8* %22, i8* %23, i32 %24, i32 %25, i32 %26)
br label %64
28: ; preds = %4
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %11
store i32 0, i32* %12
br label %31
31: ; preds = %53, %28
%32 = load i32, i32* %12
%33 = load i32, i32* %5
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %56
35: ; preds = %31
%36 = call i64 (...) @fork()
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %52
38: ; preds = %35
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = call i32 (...) @getpid()
%44 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%46 = load i8*, i8** %9
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = load i32, i32* %8
%50 = call i32 @generate_dna(i8* %45, i8* %46, i32 %47, i32 %48, i32 %49)
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %35
br label %53
53: ; preds = %52
%54 = load i32, i32* %12
%55 = add nsw i32 %54, 1
store i32 %55, i32* %12
br label %31
56: ; preds = %31
br label %57
57: ; preds = %61, %56
%58 = load i32, i32* %5
%59 = add nsw i32 %58, -1
store i32 %59, i32* %5
%60 = icmp ne i32 %58, 0
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 @wait(i32* null)
br label %57
63: ; preds = %57
br label %64
64: ; preds = %63, %21
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [4 x i8] c"%d-\00"
define void @do_work(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [80 x i8]
%6 = tail call i8* @generate_random_dna(i32 %2)
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%8 = call i32 @gethostname(i8* %7, i32 79)
%9 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %0, 1
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = call i32 @generate_dna(i8* %7, i8* %6, i32 %1, i32 %2, i32 %3)
br label %37
13: ; preds = %4
%14 = call i32 @strlen(i8* %7)
%15 = icmp sgt i32 %0, 0
br i1 %15, label %20, label %18
16: ; preds = %20
%17 = icmp eq i32 %24, %0
br i1 %17, label %18, label %20
18: ; preds = %16, %13
%19 = icmp eq i32 %0, 0
br i1 %19, label %37, label %32
20: ; preds = %13, %16
%21 = phi i32 [ %24, %16 ], [ 0, %13 ]
%22 = call i64 (...) @fork()
%23 = icmp eq i64 %22, 0
%24 = add nuw nsw i32 %21, 1
br i1 %23, label %25, label %16
25: ; preds = %20
%26 = sext i32 %14 to i64
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %26
%28 = call i32 (...) @getpid()
%29 = call i32 @sprintf(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = call i32 @generate_dna(i8* %7, i8* %6, i32 %1, i32 %2, i32 %3)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %18, %32
%33 = phi i32 [ %34, %32 ], [ %0, %18 ]
%34 = add nsw i32 %33, -1
%35 = call i32 @wait(i32* null)
%36 = icmp eq i32 %34, 0
br i1 %36, label %37, label %32
37: ; preds = %32, %18, %11
ret void
}