#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 contaRepeticao(int *, size_t, int);
int /*<<< orphan*/ printf(char *, ...);
int *realloc(int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  size_t arrayCount = 0;
  size_t arrayCapacity = 0;
  int *array = 0;
  for (;;) {
    if (arrayCount == arrayCapacity) {
      arrayCapacity += 20;
      array = realloc(array, sizeof(*array) * arrayCapacity);
    }
    printf("Introduza um número: ");
    scanf("%d", array + arrayCount++);
    if (array[arrayCount - 1] < 0) {
      break;
    }
  }
  int searchFor;
  printf("Número a pesquisar: ");
  scanf("%d", &searchFor);
  int rep = contaRepeticao(array, arrayCount - 1, searchFor);
  printf("Maior sequência de números %d tem tamanho %d\n", searchFor, rep);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1198 <main+0x58>
mov    -0x18(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe50(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    11e7 <main+0xa7>
jmp    11ec <main+0xac>
jmp    1167 <main+0x27>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe16(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x24(%rbp),%edx
call   1040 <contaRepeticao@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xec5(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    118c <main+0x4c>
xchg   %ax,%ax
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x1(%r13),%r14
lea    (%r12,%rbx,1),%rsi
mov    %r15,%rdi
call   1060 <scanf@plt>
add    $0x4,%rbx
cmpl   $0x0,(%r12,%r13,4)
mov    %r14,%r13
js     11a9 <main+0x69>
cmp    %rbp,%r13
jne    1160 <main+0x20>
add    $0x14,%rbp
lea    0x0(,%rbp,4),%esi
mov    %r12,%rdi
call   1050 <realloc@plt>
mov    %rax,%r12
jmp    1160 <main+0x20>
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe59(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edx
add    $0xffffffffffffffff,%r14
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <contaRepeticao@plt>
mov    0x4(%rsp),%esi
lea    0xe4a(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Introduza um n\C3\BAmero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"N\C3\BAmero a pesquisar: \00"
@.str.3 = [48 x i8] c"Maior sequ\C3\AAncia de n\C3\BAmeros %d tem tamanho %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %2
store i64 0, i64* %3
store i32* null, i32** %4
br label %7
7: ; preds = %33, %0
%8 = load i64, i64* %2
%9 = load i64, i64* %3
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = load i64, i64* %3
%13 = add i64 %12, 20
store i64 %13, i64* %3
%14 = load i32*, i32** %4
%15 = load i64, i64* %3
%16 = mul i64 4, %15
%17 = trunc i64 %16 to i32
%18 = call i32* @realloc(i32* %14, i32 %17)
store i32* %18, i32** %4
br label %19
19: ; preds = %11, %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%21 = load i32*, i32** %4
%22 = load i64, i64* %2
%23 = add i64 %22, 1
store i64 %23, i64* %2
%24 = getelementptr inbounds i32, i32* %21, i64 %22
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %24)
%26 = load i32*, i32** %4
%27 = load i64, i64* %2
%28 = sub i64 %27, 1
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %19
br label %34
33: ; preds = %19
br label %7
34: ; preds = %32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%37 = load i32*, i32** %4
%38 = load i64, i64* %2
%39 = sub i64 %38, 1
%40 = load i32, i32* %5
%41 = call i32 @contaRepeticao(i32* %37, i64 %39, i32 %40)
store i32 %41, i32* %6
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Introduza um n\C3\BAmero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"N\C3\BAmero a pesquisar: \00"
@.str.3 = [48 x i8] c"Maior sequ\C3\AAncia de n\C3\BAmeros %d tem tamanho %d\0A\00"
define i32 @main() {
%1 = alloca i32
br label %2
2: ; preds = %12, %0
%3 = phi i64 [ 0, %0 ], [ %13, %12 ]
%4 = phi i32* [ null, %0 ], [ %14, %12 ]
%5 = phi i64 [ 0, %0 ], [ %16, %12 ]
%6 = icmp eq i64 %5, %3
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = add i64 %3, 20
%9 = trunc i64 %8 to i32
%10 = shl i32 %9, 2
%11 = tail call i32* @realloc(i32* %4, i32 %10)
br label %12
12: ; preds = %7, %2
%13 = phi i64 [ %8, %7 ], [ %3, %2 ]
%14 = phi i32* [ %11, %7 ], [ %4, %2 ]
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%16 = add i64 %5, 1
%17 = getelementptr inbounds i32, i32* %14, i64 %5
%18 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%19 = load i32, i32* %17
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %2
21: ; preds = %12
%22 = bitcast i32* %1 to i8*
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%25 = load i32, i32* %1
%26 = call i32 @contaRepeticao(i32* %14, i64 %5, i32 %25)
%27 = load i32, i32* %1
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %26)
ret i32 0
}