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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int random_bet();
int /*<<< orphan*/ read(int, int *, int);
int result(int, int);
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ write(int, int *, int);
int main() {
  int dados_i[2][2], dados_o[2][2];
  pid_t pid;
  int i, players = 2, games = 5, aposta, resultado, vitorias[2][3], leitura[2],
         status;
  for (i = 0; i < players; i++) {
    pipe(dados_i[i]);
    pipe(dados_o[i]);
    vitorias[i][0] = 0;
    vitorias[i][1] = 0;
    vitorias[i][2] = 0;
  }
  for (i = 0; i < players; i++) {
    pid = fork();
    if (pid == 0) {
      break;
    }
    if (pid < 0) {
      perror("Erro no fork()");
    }
  }
  for (games; games > 0; games--) {
    if (pid == 0) {
      aposta = random_bet();
      write(dados_i[i][1], &aposta, sizeof(int));
      read(dados_o[i][0], &resultado, sizeof(int));
      if (resultado == 0) {
        printf("Jogador %d : Empatei!\n", i);
      } else if (resultado == 1) {
        if (i == 0) {
          printf("Jogador %d : Ganhei!\n", i);
        } else {
          printf("Jogador %d : Perdi!\n", i);
        }
      } else {
        if (i == 0) {
          printf("Jogador %d : Perdi!\n", i);
        } else {
          printf("Jogador %d : Ganhei!\n", i);
        }
      }
      if (games == 1) {
        exit(0);
      }
    } else {
      int acertar = random_bet();
      int leitura[2];
      for (i = 0; i < players; i++) {
        read(dados_i[i][0], &(leitura[i]), sizeof(int));
      }
      int ronda = result(leitura[0], leitura[1]);
      write(dados_o[0][1], &ronda, sizeof(int));
      write(dados_o[1][1], &ronda, sizeof(int));
      if (ronda == 0) {
        vitorias[0][0]++;
        vitorias[1][0]++;
      }
      if (ronda == 1) {
        vitorias[0][1]++;
        vitorias[1][2]++;
      }
      if (ronda == 2) {
        vitorias[0][2]++;
        vitorias[1][1]++;
      }
      for (i = 0; i < players; i++) {
        printf("O jogador %d tem %d vitorias, %d derrotas e %d empates\n",
               (i + 1), vitorias[i][1], vitorias[i][2], vitorias[i][0]);
      }
    }
  }
  if (pid > 0) {
    for (i = 0; i < players; i++) {
      wait(&status);
    }
    printf("\nResutados Finais:\n");
    for (i = 0; i < players; i++) {
      printf("O jogador %d tem %d vitorias, %d derrotas e %d empates\n",
             (i + 1), vitorias[i][1], vitorias[i][2], vitorias[i][0]);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x40(%rbp)
movl   $0x5,-0x44(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    124a <main+0xaa>
movslq -0x3c(%rbp),%rax
lea    -0x20(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
call   1050 <pipe@plt>
movslq -0x3c(%rbp),%rax
lea    -0x30(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
call   1050 <pipe@plt>
movslq -0x3c(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0x0,(%rax)
movslq -0x3c(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0x0,0x4(%rax)
movslq -0x3c(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0x0,0x8(%rax)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11c7 <main+0x27>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    12a2 <main+0x102>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1278 <main+0xd8>
jmp    12a2 <main+0x102>
cmpq   $0x0,-0x38(%rbp)
jge    128f <main+0xef>
lea    0xd76(%rip),%rdi
call   1080 <perror@plt>
jmp    1294 <main+0xf4>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1251 <main+0xb1>
cmpl   $0x0,-0x44(%rbp)
jle    150c <main+0x36c>
cmpq   $0x0,-0x38(%rbp)
jne    139e <main+0x1fe>
mov    $0x0,%al
call   10a0 <random_bet@plt>
mov    %eax,-0x48(%rbp)
movslq -0x3c(%rbp),%rax
mov    -0x1c(%rbp,%rax,8),%edi
lea    -0x48(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%edi
lea    -0x4c(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmpl   $0x0,-0x4c(%rbp)
jne    130d <main+0x16d>
mov    -0x3c(%rbp),%esi
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1388 <main+0x1e8>
cmpl   $0x1,-0x4c(%rbp)
jne    134d <main+0x1ad>
cmpl   $0x0,-0x3c(%rbp)
jne    1337 <main+0x197>
mov    -0x3c(%rbp),%esi
lea    0xcfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1348 <main+0x1a8>
mov    -0x3c(%rbp),%esi
lea    0xcfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1383 <main+0x1e3>
cmpl   $0x0,-0x3c(%rbp)
jne    136d <main+0x1cd>
mov    -0x3c(%rbp),%esi
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    137e <main+0x1de>
mov    -0x3c(%rbp),%esi
lea    0xcaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1383 <main+0x1e3>
jmp    1388 <main+0x1e8>
cmpl   $0x1,-0x44(%rbp)
jne    1399 <main+0x1f9>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    14f9 <main+0x359>
mov    $0x0,%al
call   10a0 <random_bet@plt>
mov    %eax,-0x80(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    13ed <main+0x24d>
movslq -0x3c(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%edi
movslq -0x3c(%rbp),%rax
lea    -0x88(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    13af <main+0x20f>
mov    -0x88(%rbp),%edi
mov    -0x84(%rbp),%esi
call   1070 <result@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x8c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
lea    -0x8c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmpl   $0x0,-0x8c(%rbp)
jne    144b <main+0x2ab>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
cmpl   $0x1,-0x8c(%rbp)
jne    146a <main+0x2ca>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x2,-0x8c(%rbp)
jne    1489 <main+0x2e9>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    14f4 <main+0x354>
mov    -0x3c(%rbp),%esi
add    $0x1,%esi
movslq -0x3c(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x4(%rax),%edx
movslq -0x3c(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%ecx
movslq -0x3c(%rbp),%rdi
lea    -0x70(%rbp),%rax
imul   $0xc,%rdi,%rdi
add    %rdi,%rax
mov    (%rax),%r8d
lea    0xb72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1490 <main+0x2f0>
jmp    14f9 <main+0x359>
jmp    14fe <main+0x35e>
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    12a2 <main+0x102>
cmpq   $0x0,-0x38(%rbp)
jle    15bf <main+0x41f>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    1541 <main+0x3a1>
lea    -0x7c(%rbp),%rdi
call   10b0 <wait@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    151e <main+0x37e>
lea    0xb41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    15ba <main+0x41a>
mov    -0x3c(%rbp),%esi
add    $0x1,%esi
movslq -0x3c(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x4(%rax),%edx
movslq -0x3c(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%ecx
movslq -0x3c(%rbp),%rdi
lea    -0x70(%rbp),%rax
imul   $0xc,%rdi,%rdi
add    %rdi,%rax
mov    (%rax),%r8d
lea    0xaac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1556 <main+0x3b6>
jmp    15bf <main+0x41f>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0x40(%rsp),%rdi
call   1060 <pipe@plt>
lea    0x30(%rsp),%rdi
call   1060 <pipe@plt>
lea    0x48(%rsp),%rdi
call   1060 <pipe@plt>
lea    0x38(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
je     121d <main+0x6d>
js     14b5 <main+0x305>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
je     1222 <main+0x72>
mov    %rax,%r15
mov    $0x2,%r13d
jns    122b <main+0x7b>
lea    0xdea(%rip),%rdi
call   1090 <perror@plt>
jmp    122b <main+0x7b>
xor    %r13d,%r13d
jmp    1228 <main+0x78>
mov    $0x1,%r13d
xor    %r15d,%r15d
mov    $0x5,%r14d
lea    0x2c(%rsp),%rbx
lea    0x28(%rsp),%r12
movl   $0x0,0x18(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,0x8(%rsp)
jmp    12d3 <main+0x123>
nopl   (%rax)
addl   $0x1,0xc(%rsp)
addl   $0x1,0x10(%rsp)
mov    %r13,%rbx
lea    0xdcd(%rip),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    0x4(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%r13d
mov    %rbp,%rdi
mov    $0x2,%esi
mov    0x10(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x14(%rsp),%r8d
xor    %eax,%eax
call   1050 <printf@plt>
lea    -0x1(%r14),%eax
cmp    $0x1,%r14d
mov    %eax,%r14d
jbe    143f <main+0x28f>
test   %r15,%r15
je     1380 <main+0x1d0>
mov    %rbx,%r13
xor    %eax,%eax
call   10b0 <random_bet@plt>
mov    0x40(%rsp),%edi
lea    0x1c(%rsp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x48(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x1c(%rsp),%edi
mov    0x20(%rsp),%esi
call   1080 <result@plt>
mov    %eax,%ebp
mov    %eax,0x24(%rsp)
mov    0x34(%rsp),%edi
lea    0x24(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    0x3c(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0x2,%ebp
je     1270 <main+0xc0>
cmp    $0x1,%ebp
je     1430 <main+0x280>
test   %ebp,%ebp
mov    %r13,%rbx
jne    127d <main+0xcd>
addl   $0x1,0x8(%rsp)
addl   $0x1,0x14(%rsp)
jmp    127d <main+0xcd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%r13d
lea    0xc9c(%rip),%rbp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <random_bet@plt>
mov    %eax,0x2c(%rsp)
mov    0x44(%rsp,%r13,8),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    0x30(%rsp,%r13,8),%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x28(%rsp),%eax
cmp    $0x1,%eax
je     13e0 <main+0x230>
test   %eax,%eax
jne    13f0 <main+0x240>
lea    0xc3c(%rip),%rdi
jmp    13f8 <main+0x248>
cs nopw 0x0(%rax,%rax,1)
nop
test   %r13,%r13
je     141e <main+0x26e>
lea    0xc50(%rip),%rdi
jmp    13f8 <main+0x248>
xchg   %ax,%ax
test   %r13,%r13
je     1425 <main+0x275>
mov    %rbp,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x1,%r14d
je     14c6 <main+0x316>
add    $0xffffffff,%r14d
test   %r15,%r15
je     1390 <main+0x1e0>
jmp    12dc <main+0x12c>
mov    %rbp,%rdi
xor    %esi,%esi
jmp    13fb <main+0x24b>
lea    0xc10(%rip),%rdi
xor    %esi,%esi
jmp    13fb <main+0x24b>
addl   $0x1,0x4(%rsp)
addl   $0x1,0x18(%rsp)
jmp    127a <main+0xca>
test   %r15,%r15
jle    14a4 <main+0x2f4>
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <wait@plt>
mov    %rbx,%rdi
call   10c0 <wait@plt>
lea    0xc29(%rip),%rdi
call   1030 <puts@plt>
lea    0xbe5(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    0x4(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    0x10(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x14(%rsp),%r8d
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb44(%rip),%rdi
call   1090 <perror@plt>
jmp    11f8 <main+0x48>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Erro no fork()\00"
@.str.1 = [23 x i8] c"Jogador %d : Empatei!\0A\00"
@.str.2 = [22 x i8] c"Jogador %d : Ganhei!\0A\00"
@.str.3 = [21 x i8] c"Jogador %d : Perdi!\0A\00"
@.str.4 = [56 x i8] c"O jogador %d tem %d vitorias, %d derrotas e %d empates\0A\00"
@.str.5 = [20 x i8] c"\0AResutados Finais:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x [2 x i32]]
%3 = alloca [2 x [2 x i32]]
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2 x [3 x i32]]
%11 = alloca [2 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca [2 x i32]
%15 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %6
store i32 5, i32* %7
store i32 0, i32* %5
br label %16
16: ; preds = %43, %0
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %46
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 %22
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 0
%25 = call i32 @pipe(i32* %24)
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %3, i64 0, i64 %27
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %28, i64 0, i64 0
%30 = call i32 @pipe(i32* %29)
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 %32
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %33, i64 0, i64 0
store i32 0, i32* %34
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 %36
%38 = getelementptr inbounds [3 x i32], [3 x i32]* %37, i64 0, i64 1
store i32 0, i32* %38
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 %40
%42 = getelementptr inbounds [3 x i32], [3 x i32]* %41, i64 0, i64 2
store i32 0, i32* %42
br label %43
43: ; preds = %20
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %16
46: ; preds = %16
store i32 0, i32* %5
br label %47
47: ; preds = %62, %46
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %65
51: ; preds = %47
%52 = call i64 (...) @fork()
store i64 %52, i64* %4
%53 = load i64, i64* %4
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %51
br label %65
56: ; preds = %51
%57 = load i64, i64* %4
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
br label %62
62: ; preds = %61
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %47
65: ; preds = %55, %47
%66 = load i32, i32* %7
br label %67
67: ; preds = %219, %65
%68 = load i32, i32* %7
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %222
70: ; preds = %67
%71 = load i64, i64* %4
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %122
73: ; preds = %70
%74 = call i32 (...) @random_bet()
store i32 %74, i32* %8
%75 = load i32, i32* %5
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 %76
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %77, i64 0, i64 1
%79 = load i32, i32* %78
%80 = call i32 @write(i32 %79, i32* %8, i32 4)
%81 = load i32, i32* %5
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %3, i64 0, i64 %82
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %83, i64 0, i64 0
%85 = load i32, i32* %84
%86 = call i32 @read(i32 %85, i32* %9, i32 4)
%87 = load i32, i32* %9
%88 = icmp eq i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %73
%90 = load i32, i32* %5
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %90)
br label %116
92: ; preds = %73
%93 = load i32, i32* %9
%94 = icmp eq i32 %93, 1
br i1 %94, label %95, label %105
95: ; preds = %92
%96 = load i32, i32* %5
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = load i32, i32* %5
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %99)
br label %104
101: ; preds = %95
%102 = load i32, i32* %5
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %102)
br label %104
104: ; preds = %101, %98
br label %115
105: ; preds = %92
%106 = load i32, i32* %5
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %111
108: ; preds = %105
%109 = load i32, i32* %5
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %109)
br label %114
111: ; preds = %105
%112 = load i32, i32* %5
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %112)
br label %114
114: ; preds = %111, %108
br label %115
115: ; preds = %114, %104
br label %116
116: ; preds = %115, %89
%117 = load i32, i32* %7
%118 = icmp eq i32 %117, 1
br i1 %118, label %119, label %121
119: ; preds = %116
%120 = call i32 @exit(i32 0)
unreachable
121: ; preds = %116
br label %218
122: ; preds = %70
%123 = call i32 (...) @random_bet()
store i32 %123, i32* %13
store i32 0, i32* %5
br label %124
124: ; preds = %138, %122
%125 = load i32, i32* %5
%126 = load i32, i32* %6
%127 = icmp slt i32 %125, %126
br i1 %127, label %128, label %141
128: ; preds = %124
%129 = load i32, i32* %5
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 %130
%132 = getelementptr inbounds [2 x i32], [2 x i32]* %131, i64 0, i64 0
%133 = load i32, i32* %132
%134 = load i32, i32* %5
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 %135
%137 = call i32 @read(i32 %133, i32* %136, i32 4)
br label %138
138: ; preds = %128
%139 = load i32, i32* %5
%140 = add nsw i32 %139, 1
store i32 %140, i32* %5
br label %124
141: ; preds = %124
%142 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 0
%143 = load i32, i32* %142
%144 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 1
%145 = load i32, i32* %144
%146 = call i32 @result(i32 %143, i32 %145)
store i32 %146, i32* %15
%147 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %3, i64 0, i64 0
%148 = getelementptr inbounds [2 x i32], [2 x i32]* %147, i64 0, i64 1
%149 = load i32, i32* %148
%150 = call i32 @write(i32 %149, i32* %15, i32 4)
%151 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %3, i64 0, i64 1
%152 = getelementptr inbounds [2 x i32], [2 x i32]* %151, i64 0, i64 1
%153 = load i32, i32* %152
%154 = call i32 @write(i32 %153, i32* %15, i32 4)
%155 = load i32, i32* %15
%156 = icmp eq i32 %155, 0
br i1 %156, label %157, label %166
157: ; preds = %141
%158 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 0
%159 = getelementptr inbounds [3 x i32], [3 x i32]* %158, i64 0, i64 0
%160 = load i32, i32* %159
%161 = add nsw i32 %160, 1
store i32 %161, i32* %159
%162 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 1
%163 = getelementptr inbounds [3 x i32], [3 x i32]* %162, i64 0, i64 0
%164 = load i32, i32* %163
%165 = add nsw i32 %164, 1
store i32 %165, i32* %163
br label %166
166: ; preds = %157, %141
%167 = load i32, i32* %15
%168 = icmp eq i32 %167, 1
br i1 %168, label %169, label %178
169: ; preds = %166
%170 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 0
%171 = getelementptr inbounds [3 x i32], [3 x i32]* %170, i64 0, i64 1
%172 = load i32, i32* %171
%173 = add nsw i32 %172, 1
store i32 %173, i32* %171
%174 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 1
%175 = getelementptr inbounds [3 x i32], [3 x i32]* %174, i64 0, i64 2
%176 = load i32, i32* %175
%177 = add nsw i32 %176, 1
store i32 %177, i32* %175
br label %178
178: ; preds = %169, %166
%179 = load i32, i32* %15
%180 = icmp eq i32 %179, 2
br i1 %180, label %181, label %190
181: ; preds = %178
%182 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 0
%183 = getelementptr inbounds [3 x i32], [3 x i32]* %182, i64 0, i64 2
%184 = load i32, i32* %183
%185 = add nsw i32 %184, 1
store i32 %185, i32* %183
%186 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 1
%187 = getelementptr inbounds [3 x i32], [3 x i32]* %186, i64 0, i64 1
%188 = load i32, i32* %187
%189 = add nsw i32 %188, 1
store i32 %189, i32* %187
br label %190
190: ; preds = %181, %178
store i32 0, i32* %5
br label %191
191: ; preds = %214, %190
%192 = load i32, i32* %5
%193 = load i32, i32* %6
%194 = icmp slt i32 %192, %193
br i1 %194, label %195, label %217
195: ; preds = %191
%196 = load i32, i32* %5
%197 = add nsw i32 %196, 1
%198 = load i32, i32* %5
%199 = sext i32 %198 to i64
%200 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 %199
%201 = getelementptr inbounds [3 x i32], [3 x i32]* %200, i64 0, i64 1
%202 = load i32, i32* %201
%203 = load i32, i32* %5
%204 = sext i32 %203 to i64
%205 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 %204
%206 = getelementptr inbounds [3 x i32], [3 x i32]* %205, i64 0, i64 2
%207 = load i32, i32* %206
%208 = load i32, i32* %5
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 %209
%211 = getelementptr inbounds [3 x i32], [3 x i32]* %210, i64 0, i64 0
%212 = load i32, i32* %211
%213 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %197, i32 %202, i32 %207, i32 %212)
br label %214
214: ; preds = %195
%215 = load i32, i32* %5
%216 = add nsw i32 %215, 1
store i32 %216, i32* %5
br label %191
217: ; preds = %191
br label %218
218: ; preds = %217, %121
br label %219
219: ; preds = %218
%220 = load i32, i32* %7
%221 = add nsw i32 %220, -1
store i32 %221, i32* %7
br label %67
222: ; preds = %67
%223 = load i64, i64* %4
%224 = icmp sgt i64 %223, 0
br i1 %224, label %225, label %264
225: ; preds = %222
store i32 0, i32* %5
br label %226
226: ; preds = %232, %225
%227 = load i32, i32* %5
%228 = load i32, i32* %6
%229 = icmp slt i32 %227, %228
br i1 %229, label %230, label %235
230: ; preds = %226
%231 = call i32 @wait(i32* %12)
br label %232
232: ; preds = %230
%233 = load i32, i32* %5
%234 = add nsw i32 %233, 1
store i32 %234, i32* %5
br label %226
235: ; preds = %226
%236 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %5
br label %237
237: ; preds = %260, %235
%238 = load i32, i32* %5
%239 = load i32, i32* %6
%240 = icmp slt i32 %238, %239
br i1 %240, label %241, label %263
241: ; preds = %237
%242 = load i32, i32* %5
%243 = add nsw i32 %242, 1
%244 = load i32, i32* %5
%245 = sext i32 %244 to i64
%246 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 %245
%247 = getelementptr inbounds [3 x i32], [3 x i32]* %246, i64 0, i64 1
%248 = load i32, i32* %247
%249 = load i32, i32* %5
%250 = sext i32 %249 to i64
%251 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 %250
%252 = getelementptr inbounds [3 x i32], [3 x i32]* %251, i64 0, i64 2
%253 = load i32, i32* %252
%254 = load i32, i32* %5
%255 = sext i32 %254 to i64
%256 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %10, i64 0, i64 %255
%257 = getelementptr inbounds [3 x i32], [3 x i32]* %256, i64 0, i64 0
%258 = load i32, i32* %257
%259 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %243, i32 %248, i32 %253, i32 %258)
br label %260
260: ; preds = %241
%261 = load i32, i32* %5
%262 = add nsw i32 %261, 1
store i32 %262, i32* %5
br label %237
263: ; preds = %237
br label %264
264: ; preds = %263, %222
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Erro no fork()\00"
@.str.1 = [23 x i8] c"Jogador %d : Empatei!\0A\00"
@.str.2 = [22 x i8] c"Jogador %d : Ganhei!\0A\00"
@.str.3 = [21 x i8] c"Jogador %d : Perdi!\0A\00"
@.str.4 = [56 x i8] c"O jogador %d tem %d vitorias, %d derrotas e %d empates\0A\00"
@str = [19 x i8] c"\0AResutados Finais:\00"
define i32 @main() {
%1 = alloca [2 x [2 x i32]]
%2 = alloca [2 x [2 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = bitcast [2 x [2 x i32]]* %1 to i8*
%9 = bitcast [2 x [2 x i32]]* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %1, i64 0, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 0, i64 0
%16 = call i32 @pipe(i32* %15)
%17 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %1, i64 0, i64 1, i64 0
%18 = call i32 @pipe(i32* %17)
%19 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 1, i64 0
%20 = call i32 @pipe(i32* %19)
%21 = call i64 (...) @fork()
%22 = icmp eq i64 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %0
%24 = icmp slt i64 %21, 0
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %23, %25
%28 = call i64 (...) @fork()
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = icmp slt i64 %28, 0
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %30, %32, %27, %0
%35 = phi i32 [ 0, %0 ], [ 1, %27 ], [ 2, %32 ], [ 2, %30 ]
%36 = phi i64 [ 0, %0 ], [ 0, %27 ], [ %28, %32 ], [ %28, %30 ]
%37 = icmp eq i64 %36, 0
%38 = bitcast [2 x i32]* %6 to i8*
%39 = bitcast i32* %7 to i8*
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%42 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 0, i64 1
%43 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 1, i64 1
br label %44
44: ; preds = %105, %34
%45 = phi i32 [ %106, %105 ], [ 0, %34 ]
%46 = phi i32 [ %107, %105 ], [ 0, %34 ]
%47 = phi i32 [ %108, %105 ], [ 0, %34 ]
%48 = phi i32 [ %109, %105 ], [ 0, %34 ]
%49 = phi i32 [ %110, %105 ], [ 0, %34 ]
%50 = phi i32 [ %111, %105 ], [ 0, %34 ]
%51 = phi i32 [ 2, %105 ], [ %35, %34 ]
%52 = phi i32 [ %114, %105 ], [ 5, %34 ]
%53 = zext i32 %51 to i64
%54 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %1, i64 0, i64 %53, i64 1
%55 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 %53, i64 0
%56 = icmp eq i32 %51, 0
%57 = icmp eq i32 %51, 0
br i1 %37, label %58, label %82
58: ; preds = %44, %116
%59 = phi i32 [ %117, %116 ], [ %52, %44 ]
%60 = call i32 (...) @random_bet()
store i32 %60, i32* %3
%61 = load i32, i32* %54
%62 = call i32 @write(i32 %61, i32* %3, i32 4)
%63 = load i32, i32* %55
%64 = call i32 @read(i32 %63, i32* %4, i32 4)
%65 = load i32, i32* %4
switch i32 %65, label %73 [
i32 0, label %66
i32 1, label %68
]
66: ; preds = %58
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %51)
br label %78
68: ; preds = %58
br i1 %56, label %69, label %71
69: ; preds = %68
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %78
71: ; preds = %68
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %51)
br label %78
73: ; preds = %58
br i1 %57, label %74, label %76
74: ; preds = %73
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 0)
br label %78
76: ; preds = %73
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %51)
br label %78
78: ; preds = %71, %69, %76, %74, %66
%79 = icmp eq i32 %59, 1
br i1 %79, label %80, label %116
80: ; preds = %78
%81 = call i32 @exit(i32 0)
unreachable
82: ; preds = %116, %44
%83 = phi i32 [ %52, %44 ], [ %117, %116 ]
%84 = call i32 (...) @random_bet()
%85 = load i32, i32* %13
%86 = call i32 @read(i32 %85, i32* %40, i32 4)
%87 = load i32, i32* %17
%88 = call i32 @read(i32 %87, i32* %41, i32 4)
%89 = load i32, i32* %40
%90 = load i32, i32* %41
%91 = call i32 @result(i32 %89, i32 %90)
store i32 %91, i32* %7
%92 = load i32, i32* %42
%93 = call i32 @write(i32 %92, i32* %7, i32 4)
%94 = load i32, i32* %43
%95 = call i32 @write(i32 %94, i32* %7, i32 4)
switch i32 %91, label %105 [
i32 0, label %96
i32 1, label %99
i32 2, label %102
]
96: ; preds = %82
%97 = add nsw i32 %50, 1
%98 = add nsw i32 %47, 1
br label %105
99: ; preds = %82
%100 = add nsw i32 %49, 1
%101 = add nsw i32 %45, 1
br label %105
102: ; preds = %82
%103 = add nsw i32 %48, 1
%104 = add nsw i32 %46, 1
br label %105
105: ; preds = %102, %96, %99, %82
%106 = phi i32 [ %45, %82 ], [ %45, %102 ], [ %101, %99 ], [ %45, %96 ]
%107 = phi i32 [ %46, %82 ], [ %104, %102 ], [ %46, %99 ], [ %46, %96 ]
%108 = phi i32 [ %47, %82 ], [ %47, %102 ], [ %47, %99 ], [ %98, %96 ]
%109 = phi i32 [ %48, %82 ], [ %103, %102 ], [ %48, %99 ], [ %48, %96 ]
%110 = phi i32 [ %49, %82 ], [ %49, %102 ], [ %100, %99 ], [ %49, %96 ]
%111 = phi i32 [ %50, %82 ], [ %50, %102 ], [ %50, %99 ], [ %97, %96 ]
%112 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %110, i32 %109, i32 %111)
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 %107, i32 %106, i32 %108)
%114 = add nsw i32 %83, -1
%115 = icmp ugt i32 %83, 1
br i1 %115, label %44, label %118
116: ; preds = %78
%117 = add nsw i32 %59, -1
br i1 %37, label %58, label %82
118: ; preds = %105
%119 = icmp sgt i64 %36, 0
br i1 %119, label %120, label %126
120: ; preds = %118
%121 = call i32 @wait(i32* %5)
%122 = call i32 @wait(i32* %5)
%123 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %110, i32 %109, i32 %111)
%125 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 %107, i32 %106, i32 %108)
br label %126
126: ; preds = %120, %118
ret i32 0
}