#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 front(int, int);
scalar_t__ inicializa(int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int k = 0, reg, atual, max;
  int batalhoes[20];
  int jafoi[20];
  printf(" *** Envio pro front ***\n");
  if (inicializa(batalhoes)) {
    printf(" *** erro ao inicializar o vetor ***\n");
    return -1;
  }
  for (int i = 0; i < 20; i++) {
    jafoi[i] = 0;
  }
  do {
    if (0) {
      printf("Chamando seleciona pra semana: %d\n", k);
    }
    reg = -1;
    max = -1;
    for (int i = 0; i < 20; i++) {
      if (0) {
        printf("Descobrir o maior: buscando[%d]=%d\n", i, batalhoes[i]);
      }
      atual = front(i, batalhoes[i]);
      if ((atual > max) && (!jafoi[i])) {
        if (0) {
          printf("um novo maior: atual[%d]=%d, max[%d] = %d\n", i, atual, max,
                 reg);
        }
        max = atual;
        reg = i;
      }
      batalhoes[i] = atual;
    }
    if (!jafoi[reg])
      printf("Semana:"
             "\x1b[32m"
             " %d\t "
             "\x1b[0m"
             "Regimento enviado ao front: "
             "\x1b[32m"
             "%d\t"
             "\x1b[0m"
             "--  com "
             "\x1b[32m"
             " %d "
             "\x1b[0m"
             " homens.\n",
             k + 1, reg + 1, batalhoes[reg]);
    jafoi[reg] = 1;
    k++;
  } while (k < 20);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1050 <inicializa@plt>
cmp    $0x0,%rax
je     1184 <main+0x54>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b3 <main+0x183>
movl   $0x0,-0xc4(%rbp)
cmpl   $0x14,-0xc4(%rbp)
jge    11c1 <main+0x91>
movslq -0xc4(%rbp),%rax
movl   $0x0,-0xc0(%rbp,%rax,4)
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    118e <main+0x5e>
jmp    11c6 <main+0x96>
movl   $0xffffffff,-0xc(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0xc8(%rbp)
cmpl   $0x14,-0xc8(%rbp)
jge    1256 <main+0x126>
mov    -0xc8(%rbp),%edi
movslq -0xc8(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%esi
call   1040 <front@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1234 <main+0x104>
movslq -0xc8(%rbp),%rax
cmpl   $0x0,-0xc0(%rbp,%rax,4)
jne    1234 <main+0x104>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%ecx
movslq -0xc8(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    11de <main+0xae>
movslq -0xc(%rbp),%rax
cmpl   $0x0,-0xc0(%rbp,%rax,4)
jne    128a <main+0x15a>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
movslq -0xc(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xc(%rbp),%rax
movl   $0x1,-0xc0(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jl     11c6 <main+0x96>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
lea    0xf06(%rip),%rdi
call   1030 <puts@plt>
lea    0x50(%rsp),%rdi
call   1060 <inicializa@plt>
test   %rax,%rax
je     1180 <main+0x40>
lea    0xf04(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1228 <main+0xe8>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe5e(%rip),%r14
xor    %r15d,%r15d
jmp    11ca <main+0x8a>
nopw   0x0(%rax,%rax,1)
movslq %r12d,%rbx
add    $0x1,%r15d
cmpl   $0x0,(%rsp,%rbx,4)
je     1210 <main+0xd0>
movl   $0x1,(%rsp,%rbx,4)
cmp    $0x14,%r15d
je     1226 <main+0xe6>
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
mov    $0xffffffff,%r12d
jmp    11ee <main+0xae>
nopl   0x0(%rax)
mov    %eax,0x50(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x14,%rbx
je     11b0 <main+0x70>
mov    0x50(%rsp,%rbx,4),%esi
mov    %ebx,%edi
call   1050 <front@plt>
cmp    %ebp,%eax
jle    11e0 <main+0xa0>
cmpl   $0x0,(%rsp,%rbx,4)
cmove  %ebx,%r12d
cmove  %eax,%ebp
jmp    11e0 <main+0xa0>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%edx
mov    0x50(%rsp,%rbx,4),%ecx
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11bd <main+0x7d>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c" *** Envio pro front ***\0A\00"
@.str.1 = [38 x i8] c" *** erro ao inicializar o vetor ***\0A\00"
@.str.2 = [92 x i8] c"Semana:\1B[32m %d\09 \1B[0mRegimento enviado ao front: \1B[32m%d\09\1B[0m-- com \1B[32m %d \1B[0m homens.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [20 x i32]
%7 = alloca [20 x i32]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%12 = call i64 @inicializa(i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %85
16: ; preds = %0
store i32 0, i32* %8
br label %17
17: ; preds = %24, %16
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 20
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i32], [20 x i32]* %7, i64 0, i64 %22
store i32 0, i32* %23
br label %24
24: ; preds = %20
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %17
27: ; preds = %17
br label %28
28: ; preds = %81, %27
store i32 -1, i32* %3
store i32 -1, i32* %5
store i32 0, i32* %9
br label %29
29: ; preds = %56, %28
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 20
br i1 %31, label %32, label %59
32: ; preds = %29
%33 = load i32, i32* %9
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @front(i32 %33, i32 %37)
store i32 %38, i32* %4
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %51
42: ; preds = %32
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [20 x i32], [20 x i32]* %7, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %42
%49 = load i32, i32* %4
store i32 %49, i32* %5
%50 = load i32, i32* %9
store i32 %50, i32* %3
br label %51
51: ; preds = %48, %42, %32
%52 = load i32, i32* %4
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %54
store i32 %52, i32* %55
br label %56
56: ; preds = %51
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %29
59: ; preds = %29
%60 = load i32, i32* %3
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [20 x i32], [20 x i32]* %7, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = icmp ne i32 %63, 0
br i1 %64, label %75, label %65
65: ; preds = %59
%66 = load i32, i32* %2
%67 = add nsw i32 %66, 1
%68 = load i32, i32* %3
%69 = add nsw i32 %68, 1
%70 = load i32, i32* %3
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %71
%73 = load i32, i32* %72
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.2, i64 0, i64 0), i32 %67, i32 %69, i32 %73)
br label %75
75: ; preds = %65, %59
%76 = load i32, i32* %3
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [20 x i32], [20 x i32]* %7, i64 0, i64 %77
store i32 1, i32* %78
%79 = load i32, i32* %2
%80 = add nsw i32 %79, 1
store i32 %80, i32* %2
br label %81
81: ; preds = %75
%82 = load i32, i32* %2
%83 = icmp slt i32 %82, 20
br i1 %83, label %28, label %84
84: ; preds = %81
store i32 0, i32* %1
br label %85
85: ; preds = %84, %14
%86 = load i32, i32* %1
ret i32 %86
}

LLVM IR (-O2):
@.str.2 = [92 x i8] c"Semana:\1B[32m %d\09 \1B[0mRegimento enviado ao front: \1B[32m%d\09\1B[0m-- com \1B[32m %d \1B[0m homens.\0A\00"
@str = [25 x i8] c" *** Envio pro front ***\00"
@str.3 = [37 x i8] c" *** erro ao inicializar o vetor ***\00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca [20 x i32]
%3 = bitcast [20 x i32]* %2 to i8*
%4 = bitcast [20 x i32]* %1 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%7 = call i64 @inicializa(i32* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
br label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.3, i64 0, i64 0))
br label %47
12: ; preds = %9, %45
%13 = phi i32 [ %19, %45 ], [ 0, %9 ]
br label %20
14: ; preds = %35
%15 = sext i32 %36 to i64
%16 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
%19 = add nuw nsw i32 %13, 1
br i1 %18, label %40, label %45
20: ; preds = %12, %35
%21 = phi i64 [ 0, %12 ], [ %38, %35 ]
%22 = phi i32 [ -1, %12 ], [ %37, %35 ]
%23 = phi i32 [ -1, %12 ], [ %36, %35 ]
%24 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %21
%25 = load i32, i32* %24
%26 = trunc i64 %21 to i32
%27 = call i32 @front(i32 %26, i32 %25)
%28 = icmp sgt i32 %27, %22
br i1 %28, label %29, label %35
29: ; preds = %20
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %21
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i32 %26, i32 %23
%34 = select i1 %32, i32 %27, i32 %22
br label %35
35: ; preds = %29, %20
%36 = phi i32 [ %23, %20 ], [ %33, %29 ]
%37 = phi i32 [ %22, %20 ], [ %34, %29 ]
store i32 %27, i32* %24
%38 = add nuw nsw i64 %21, 1
%39 = icmp eq i64 %38, 20
br i1 %39, label %14, label %20
40: ; preds = %14
%41 = add nsw i32 %36, 1
%42 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %15
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([92 x i8], [92 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %41, i32 %43)
br label %45
45: ; preds = %14, %40
store i32 1, i32* %16
%46 = icmp eq i32 %19, 20
br i1 %46, label %47, label %12
47: ; preds = %45, %10
%48 = phi i32 [ -1, %10 ], [ 0, %45 ]
ret i32 %48
}