#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 */
struct timeval {
  float tv_usec;
  scalar_t__ tv_sec;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, float, float);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  struct timeval start_time;
  struct timeval stop_time;
  float drift;
  int count;
  int child_no;
  pid_t rtn = 1;
  for (count = 0; count < 3; count++) {
    if (rtn > 0) {
      rtn = fork();
    } else {
      break;
    }
  }
  if (rtn == 0) {
    child_no = count;
    gettimeofday(&start_time, NULL);
    for (count = 0; count < 1000; count++) {
      usleep(1000);
    }
    gettimeofday(&stop_time, NULL);
    drift = (float)(stop_time.tv_sec - start_time.tv_sec);
    drift += (stop_time.tv_usec - start_time.tv_usec) / (float)1000000;
    printf("Filho #%d -- desvio total: %.5f -- desvio medio: %.5f\n", child_no,
           drift - 1000 * 1000 / (float)1000000,
           (drift - 1000 * 1000 / (float)1000000) / 1000);
  } else {
    for (count = 0; count < 3; count++) {
      wait(NULL);
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x48(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x3,-0x38(%rbp)
jge    11c2 <main+0x62>
cmpq   $0x0,-0x48(%rbp)
jle    11aa <main+0x4a>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x48(%rbp)
jmp    11af <main+0x4f>
jmp    11c2 <main+0x62>
jmp    11b4 <main+0x54>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1185 <main+0x25>
cmpq   $0x0,-0x48(%rbp)
jne    128d <main+0x12d>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0x3e8,-0x38(%rbp)
jge    120c <main+0xac>
mov    $0x3e8,%edi
call   1080 <usleep@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11e7 <main+0x87>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x28(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x30(%rbp),%xmm0
subss  -0x20(%rbp),%xmm0
movss  0xdcb(%rip),%xmm1
divss  %xmm1,%xmm0
addss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x3c(%rbp),%esi
movss  -0x34(%rbp),%xmm0
movss  0xda9(%rip),%xmm1
subss  %xmm1,%xmm0
movss  -0x34(%rbp),%xmm1
movss  0xd98(%rip),%xmm2
subss  %xmm2,%xmm1
movss  0xd88(%rip),%xmm2
divss  %xmm2,%xmm1
lea    0xd89(%rip),%rdi
call   1030 <printf@plt>
jmp    12ba <main+0x15a>
movl   $0x0,-0x38(%rbp)
cmpl   $0x3,-0x38(%rbp)
jge    12b5 <main+0x155>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1294 <main+0x134>
jmp    12ba <main+0x15a>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%ebp
xor    %eax,%eax
call   1070 <fork@plt>
lea    0x1(%rbp),%ebx
cmp    $0x1,%ebp
ja     1186 <main+0x26>
test   %rax,%rax
jg     1170 <main+0x10>
test   %rax,%rax
jne    120a <main+0xaa>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x3e8,%ebp
nopl   0x0(%rax)
mov    $0x3e8,%edi
call   1080 <usleep@plt>
add    $0xffffffff,%ebp
jne    11a0 <main+0x40>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x10(%rsp),%rax
sub    0x20(%rsp),%rax
cvtsi2ss %rax,%xmm1
movss  0x8(%rsp),%xmm0
subss  0x18(%rsp),%xmm0
divss  0xe22(%rip),%xmm0
addss  %xmm1,%xmm0
addss  0xe1a(%rip),%xmm0
movaps %xmm0,%xmm1
divss  0xe13(%rip),%xmm1
lea    0xe10(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { float, i64 }
@.str = [55 x i8] c"Filho #%d -- desvio total: %.5f -- desvio medio: %.5f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1, i64* %11
store i32 0, i32* %9
br label %12
12: ; preds = %22, %2
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i64, i64* %11
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i64 (...) @fork()
store i64 %19, i64* %11
br label %21
20: ; preds = %15
br label %25
21: ; preds = %18
br label %22
22: ; preds = %21
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
store i32 %24, i32* %9
br label %12
25: ; preds = %20, %12
%26 = load i64, i64* %11
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %62
28: ; preds = %25
%29 = load i32, i32* %9
store i32 %29, i32* %10
%30 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
store i32 0, i32* %9
br label %31
31: ; preds = %36, %28
%32 = load i32, i32* %9
%33 = icmp slt i32 %32, 1000
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = call i32 @usleep(i32 1000)
br label %36
36: ; preds = %34
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %31
39: ; preds = %31
%40 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%42 = load i64, i64* %41
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%44 = load i64, i64* %43
%45 = sub nsw i64 %42, %44
%46 = sitofp i64 %45 to float
store float %46, float* %8
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%48 = load float, float* %47
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%50 = load float, float* %49
%51 = fsub float %48, %50
%52 = fdiv float %51, 1.000000e+06
%53 = load float, float* %8
%54 = fadd float %53, %52
store float %54, float* %8
%55 = load i32, i32* %10
%56 = load float, float* %8
%57 = fsub float %56, 1.000000e+00
%58 = load float, float* %8
%59 = fsub float %58, 1.000000e+00
%60 = fdiv float %59, 1.000000e+03
%61 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %55, float %57, float %60)
br label %72
62: ; preds = %25
store i32 0, i32* %9
br label %63
63: ; preds = %68, %62
%64 = load i32, i32* %9
%65 = icmp slt i32 %64, 3
br i1 %65, label %66, label %71
66: ; preds = %63
%67 = call i32 @wait(i32* null)
br label %68
68: ; preds = %66
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %63
71: ; preds = %63
br label %72
72: ; preds = %71, %39
%73 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { float, i64 }
@.str = [55 x i8] c"Filho #%d -- desvio total: %.5f -- desvio medio: %.5f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %10, %7 ]
%9 = tail call i64 (...) @fork()
%10 = add nuw nsw i32 %8, 1
%11 = icmp ult i32 %8, 2
%12 = icmp sgt i64 %9, 0
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %7, label %14
14: ; preds = %7
%15 = icmp eq i64 %9, 0
br i1 %15, label %20, label %16
16: ; preds = %14
%17 = tail call i32 @wait(i32* null)
%18 = tail call i32 @wait(i32* null)
%19 = tail call i32 @wait(i32* null)
br label %45
20: ; preds = %14
%21 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
br label %22
22: ; preds = %20, %22
%23 = phi i32 [ 0, %20 ], [ %25, %22 ]
%24 = tail call i32 @usleep(i32 1000)
%25 = add nuw nsw i32 %23, 1
%26 = icmp eq i32 %25, 1000
br i1 %26, label %27, label %22
27: ; preds = %22
%28 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%30 = load i64, i64* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%32 = load i64, i64* %31
%33 = sub nsw i64 %30, %32
%34 = sitofp i64 %33 to float
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%36 = load float, float* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%38 = load float, float* %37
%39 = fsub float %36, %38
%40 = fdiv float %39, 1.000000e+06
%41 = fadd float %40, %34
%42 = fadd float %41, -1.000000e+00
%43 = fdiv float %42, 1.000000e+03
%44 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %10, float %42, float %43)
br label %45
45: ; preds = %16, %27
%46 = tail call i32 @exit(i32 0)
unreachable
}