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

/* Variables and functions */
scalar_t__ dowait(int, int /*<<< orphan*/);
int /*<<< orphan*/ spawnv(char *, char **);
int /*<<< orphan*/ warnx(char *, ...);
void triple(const char *prog) {
  pid_t pids[3];
  int i, failures = 0;
  char *args[2];
  args[0] = (char *)prog;
  args[1] = NULL;
  warnx("Starting: running three copies of %s...", prog);
  for (i = 0; i < 3; i++) {
    pids[i] = spawnv(args[0], args);
  }
  for (i = 0; i < 3; i++) {
    failures += dowait(i, pids[i]);
  }
  if (failures > 0) {
    warnx("%d failures", failures);
  } else {
    warnx("Congratulations! You passed.");
  }
}


x86 assembly (clang, -O0):
<triple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <warnx@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    119b <triple+0x6b>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <spawnv@plt>
mov    %eax,%ecx
movslq -0x18(%rbp),%rax
mov    %ecx,-0x14(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116c <triple+0x3c>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11d7 <triple+0xa7>
mov    -0x18(%rbp),%edi
movslq -0x18(%rbp),%rax
mov    -0x14(%rbp,%rax,4),%esi
call   1030 <dowait@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a2 <triple+0x72>
cmpl   $0x0,-0x1c(%rbp)
jle    11f7 <triple+0xc7>
mov    -0x1c(%rbp),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <warnx@plt>
jmp    1205 <triple+0xd5>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <warnx@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<triple>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rdi,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <warnx@plt>
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <spawnv@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1050 <spawnv@plt>
mov    %eax,%ebp
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1050 <spawnv@plt>
mov    %eax,%r14d
xor    %edi,%edi
mov    %ebx,%esi
call   1030 <dowait@plt>
mov    %rax,%rbx
mov    $0x1,%edi
mov    %ebp,%esi
call   1030 <dowait@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    $0x2,%edi
mov    %r14d,%esi
call   1030 <dowait@plt>
add    %ebp,%eax
test   %eax,%eax
jle    11c8 <triple+0x98>
lea    0xe6b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <warnx@plt>
jmp    11d6 <triple+0xa6>
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1040 <warnx@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Starting: running three copies of %s...\00"
@.str.1 = [12 x i8] c"%d failures\00"
@.str.2 = [29 x i8] c"Congratulations! You passed.\00"
define void @triple(i8* %0) {
%2 = alloca i8*
%3 = alloca [3 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i8*]
store i8* %0, i8** %2
store i32 0, i32* %5
%7 = load i8*, i8** %2
%8 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
store i8* %7, i8** %8
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 1
store i8* null, i8** %9
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %10)
store i32 0, i32* %4
br label %12
12: ; preds = %23, %1
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%17 = load i8*, i8** %16
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%19 = call i32 @spawnv(i8* %17, i8** %18)
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 %21
store i32 %19, i32* %22
br label %23
23: ; preds = %15
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %12
26: ; preds = %12
store i32 0, i32* %4
br label %27
27: ; preds = %41, %26
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 3
br i1 %29, label %30, label %44
30: ; preds = %27
%31 = load i32, i32* %4
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i64 @dowait(i32 %31, i32 %35)
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = add nsw i64 %38, %36
%40 = trunc i64 %39 to i32
store i32 %40, i32* %5
br label %41
41: ; preds = %30
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %27
44: ; preds = %27
%45 = load i32, i32* %5
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %5
%49 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %48)
br label %52
50: ; preds = %44
%51 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %47
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"Starting: running three copies of %s...\00"
@.str.1 = [12 x i8] c"%d failures\00"
@.str.2 = [29 x i8] c"Congratulations! You passed.\00"
define void @triple(i8* %0) {
%2 = alloca [2 x i8*]
%3 = bitcast [2 x i8*]* %2 to i8*
%4 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
store i8* %0, i8** %4
%5 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
store i8* null, i8** %5
%6 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @spawnv(i8* %0, i8** %4)
%8 = load i8*, i8** %4
%9 = call i32 @spawnv(i8* %8, i8** %4)
%10 = load i8*, i8** %4
%11 = call i32 @spawnv(i8* %10, i8** %4)
%12 = call i64 @dowait(i32 0, i32 %7)
%13 = trunc i64 %12 to i32
%14 = call i64 @dowait(i32 1, i32 %9)
%15 = trunc i64 %14 to i32
%16 = add i32 %13, %15
%17 = call i64 @dowait(i32 2, i32 %11)
%18 = trunc i64 %17 to i32
%19 = add i32 %16, %18
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %25
23: ; preds = %1
%24 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
ret void
}