#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*/ bloco;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strstr(char *, char const *);
void buscarRA(const char *nomeArquivo, const char *ra) {
  char nomeArquivoEntradaComExtensao[25];
  char nomeArquivoSaidaComExtensao[25];
  strcpy(nomeArquivoEntradaComExtensao, nomeArquivo);
  strcpy(nomeArquivoSaidaComExtensao, nomeArquivo);
  strcat(nomeArquivoEntradaComExtensao, ".dat");
  strcat(nomeArquivoSaidaComExtensao, ".out");
  FILE *arquivoEntrada = fopen(nomeArquivoEntradaComExtensao, "rb");
  FILE *arquivoSaida = fopen(nomeArquivoSaidaComExtensao, "a");
  if (!arquivoEntrada) {
    fprintf(stderr, "Erro ao abrir o arquivo %s!\n",
            nomeArquivoEntradaComExtensao);
    exit(EXIT_FAILURE);
  }
  if (!arquivoSaida) {
    fprintf(stderr, "Erro ao criar o arquivo %s!\n",
            nomeArquivoSaidaComExtensao);
    exit(EXIT_FAILURE);
  }
  char bloco[512];
  char *inicioRegistro = NULL;
  do {
    fread(bloco, sizeof(bloco), 1, arquivoEntrada);
    inicioRegistro = strstr(bloco, ra);
  } while (!inicioRegistro && !feof(arquivoEntrada));
  if (inicioRegistro) {
    char *finalRegistro = strchr(inicioRegistro, 0x0A);
    *finalRegistro = '\0';
    char *finalCampo = strchr(inicioRegistro, 0x0D);
    while (finalCampo && finalCampo < finalRegistro - 1) {
      *finalCampo = ':';
      finalCampo = strchr(inicioRegistro, 0x0D);
    }
    *finalCampo = '\n';
    *finalRegistro = '\0';
    fprintf(arquivoSaida, "%s", inicioRegistro);
  } else {
    fprintf(arquivoSaida, "*\n");
  }
  fclose(arquivoEntrada);
  fclose(arquivoSaida);
}


x86 assembly (clang, -O0):
<buscarRA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x30(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x50(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x30(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    124a <buscarRA+0xaa>
mov    0x2db9(%rip),%rax
movslq (%rax),%rdi
lea    -0x30(%rbp),%rdx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x60(%rbp)
jne    127f <buscarRA+0xdf>
mov    0x2d84(%rip),%rax
movslq (%rax),%rdi
lea    -0x50(%rbp),%rdx
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
movq   $0x0,-0x268(%rbp)
lea    -0x260(%rbp),%rdi
mov    -0x58(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
lea    -0x260(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10c0 <strstr@plt>
mov    %rax,-0x268(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x268(%rbp)
mov    %al,-0x279(%rbp)
jne    12e8 <buscarRA+0x148>
mov    -0x58(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x279(%rbp)
mov    -0x279(%rbp),%al
test   $0x1,%al
jne    128a <buscarRA+0xea>
cmpq   $0x0,-0x268(%rbp)
je     13de <buscarRA+0x23e>
mov    -0x268(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x270(%rbp)
mov    -0x270(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x268(%rbp),%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
mov    %rax,-0x278(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x278(%rbp)
mov    %al,-0x27a(%rbp)
je     1372 <buscarRA+0x1d2>
mov    -0x278(%rbp),%rax
mov    -0x270(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x27a(%rbp)
mov    -0x27a(%rbp),%al
test   $0x1,%al
jne    1385 <buscarRA+0x1e5>
jmp    13ac <buscarRA+0x20c>
mov    -0x278(%rbp),%rax
movb   $0x3a,(%rax)
mov    -0x268(%rbp),%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
mov    %rax,-0x278(%rbp)
jmp    133e <buscarRA+0x19e>
mov    -0x278(%rbp),%rax
movb   $0xa,(%rax)
mov    -0x270(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x60(%rbp),%rdi
mov    -0x268(%rbp),%rdx
lea    0xc77(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13f0 <buscarRA+0x250>
mov    -0x60(%rbp),%rdi
lea    0xc63(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x60(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buscarRA>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x240,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%r13
mov    %r13,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe05(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xdfb(%rip),%rsi
mov    %r13,%rdi
call   10b0 <strcat@plt>
lea    0xdf1(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r12
lea    0xde2(%rip),%rsi
mov    %r13,%rdi
call   10a0 <fopen@plt>
test   %r12,%r12
je     131d <buscarRA+0x15d>
mov    %rax,%r14
test   %rax,%rax
je     1335 <buscarRA+0x175>
lea    0x40(%rsp),%r13
nopl   (%rax)
mov    %r13,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   10e0 <strstr@plt>
test   %rax,%rax
jne    129c <buscarRA+0xdc>
mov    %r12,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1250 <buscarRA+0x90>
lea    0xdc1(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
jmp    12fc <buscarRA+0x13c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     12ea <buscarRA+0x12a>
mov    %r15,%r13
add    $0xffffffffffffffff,%r13
nopl   0x0(%rax,%rax,1)
cmp    %r13,%rax
jae    12ea <buscarRA+0x12a>
movb   $0x3a,(%rax)
mov    %rbx,%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
test   %rax,%rax
jne    12d0 <buscarRA+0x110>
movb   $0xa,(%rax)
movb   $0x0,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <fputs@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
add    $0x240,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2cbc(%rip),%rax
movslq (%rax),%rdi
lea    0xce1(%rip),%rsi
lea    0x20(%rsp),%rdx
jmp    1349 <buscarRA+0x189>
mov    0x2ca4(%rip),%rax
movslq (%rax),%rdi
lea    0xce6(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c".dat\00"
@.str.1 = [5 x i8] c".out\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.4 = [29 x i8] c"Erro ao abrir o arquivo %s!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [29 x i8] c"Erro ao criar o arquivo %s!\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [3 x i8] c"*\0A\00"
define void @buscarRA(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [25 x i8]
%6 = alloca [25 x i8]
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [512 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 0
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %7
%25 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 0
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %26, i32** %8
%27 = load i32*, i32** %7
%28 = icmp ne i32* %27, null
br i1 %28, label %37, label %29
29: ; preds = %2
%30 = load i32, i32* @stderr
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i32*
%33 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %2
%38 = load i32*, i32** %8
%39 = icmp ne i32* %38, null
br i1 %39, label %48, label %40
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = sext i32 %41 to i64
%43 = inttoptr i64 %42 to i32*
%44 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 0
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %37
store i8* null, i8** %10
br label %49
49: ; preds = %64, %48
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%51 = load i32*, i32** %7
%52 = call i32 @fread(i8* %50, i32 512, i32 1, i32* %51)
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%54 = load i8*, i8** %4
%55 = call i8* @strstr(i8* %53, i8* %54)
store i8* %55, i8** %10
br label %56
56: ; preds = %49
%57 = load i8*, i8** %10
%58 = icmp ne i8* %57, null
br i1 %58, label %64, label %59
59: ; preds = %56
%60 = load i32*, i32** %7
%61 = call i32 @feof(i32* %60)
%62 = icmp ne i32 %61, 0
%63 = xor i1 %62, true
br label %64
64: ; preds = %59, %56
%65 = phi i1 [ false, %56 ], [ %63, %59 ]
br i1 %65, label %49, label %66
66: ; preds = %64
%67 = load i8*, i8** %10
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %95
69: ; preds = %66
%70 = load i8*, i8** %10
%71 = call i8* @strchr(i8* %70, i32 10)
store i8* %71, i8** %11
%72 = load i8*, i8** %11
store i8 0, i8* %72
%73 = load i8*, i8** %10
%74 = call i8* @strchr(i8* %73, i32 13)
store i8* %74, i8** %12
br label %75
75: ; preds = %85, %69
%76 = load i8*, i8** %12
%77 = icmp ne i8* %76, null
br i1 %77, label %78, label %83
78: ; preds = %75
%79 = load i8*, i8** %12
%80 = load i8*, i8** %11
%81 = getelementptr inbounds i8, i8* %80, i64 -1
%82 = icmp ult i8* %79, %81
br label %83
83: ; preds = %78, %75
%84 = phi i1 [ false, %75 ], [ %82, %78 ]
br i1 %84, label %85, label %89
85: ; preds = %83
%86 = load i8*, i8** %12
store i8 58, i8* %86
%87 = load i8*, i8** %10
%88 = call i8* @strchr(i8* %87, i32 13)
store i8* %88, i8** %12
br label %75
89: ; preds = %83
%90 = load i8*, i8** %12
store i8 10, i8* %90
%91 = load i8*, i8** %11
store i8 0, i8* %91
%92 = load i32*, i32** %8
%93 = load i8*, i8** %10
%94 = call i32 (i32*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %93)
br label %98
95: ; preds = %66
%96 = load i32*, i32** %8
%97 = call i32 (i32*, i8*, ...) @fprintf(i32* %96, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %98
98: ; preds = %95, %89
%99 = load i32*, i32** %7
%100 = call i32 @fclose(i32* %99)
%101 = load i32*, i32** %8
%102 = call i32 @fclose(i32* %101)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".dat\00"
@.str.1 = [5 x i8] c".out\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.4 = [29 x i8] c"Erro ao abrir o arquivo %s!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [29 x i8] c"Erro ao criar o arquivo %s!\0A\00"
@.str.7 = [3 x i8] c"*\0A\00"
define void @buscarRA(i8* %0, i8* nocapture %1) {
%3 = alloca [25 x i8]
%4 = alloca [25 x i8]
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%8 = call i32 @strcpy(i8* %6, i8* %0)
%9 = call i32 @strcpy(i8* %7, i8* %0)
%10 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %12, null
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i32*
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = icmp eq i32* %13, null
br i1 %23, label %24, label %31
24: ; preds = %22
%25 = load i32, i32* @stderr
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i32*
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %22
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
br label %33
33: ; preds = %37, %31
%34 = call i32 @fread(i8* %32, i32 512, i32 1, i32* %12)
%35 = call i8* @strstr(i8* %32, i8* dereferenceable(1) %1)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = call i32 @feof(i32* %12)
%39 = icmp eq i32 %38, 0
br i1 %39, label %33, label %56
40: ; preds = %33
%41 = call i8* @strchr(i8* %35, i32 10)
store i8 0, i8* %41
%42 = call i8* @strchr(i8* %35, i32 13)
%43 = getelementptr inbounds i8, i8* %41, i64 -1
%44 = icmp ne i8* %42, null
%45 = icmp ult i8* %42, %43
%46 = select i1 %44, i1 %45, i1 false
br i1 %46, label %47, label %53
47: ; preds = %40, %47
%48 = phi i8* [ %49, %47 ], [ %42, %40 ]
store i8 58, i8* %48
%49 = call i8* @strchr(i8* %35, i32 13)
%50 = icmp ne i8* %49, null
%51 = icmp ult i8* %49, %43
%52 = select i1 %50, i1 %51, i1 false
br i1 %52, label %47, label %53
53: ; preds = %47, %40
%54 = phi i8* [ %42, %40 ], [ %49, %47 ]
store i8 10, i8* %54
store i8 0, i8* %41
%55 = call i32 @fputs(i8* %35, i32* %13)
br label %58
56: ; preds = %37
%57 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %13)
br label %58
58: ; preds = %56, %53
%59 = call i32 @fclose(i32* %12)
%60 = call i32 @fclose(i32* %13)
ret void
}