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

/* Variables and functions */
scalar_t__ BuscarCadena(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int, char *);
void BuscarEnFich(char *nombrefich, char *cadena) {
  FILE *pf;
  char linea[256];
  int nrolinea = 0;
  if ((pf = fopen(nombrefich, "r")) == NULL) {
    perror(nombrefich);
    return;
  }
  while (fgets(linea, sizeof(linea), pf) != NULL) {
    nrolinea++;
    if (BuscarCadena(linea, cadena))
      printf("%s[%d]: %s", nombrefich, nrolinea, linea);
  }
  fclose(pf);
}


x86 assembly (clang, -O0):
<BuscarEnFich>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x124(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a9 <BuscarEnFich+0x49>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
jmp    1221 <BuscarEnFich+0xc1>
jmp    11ae <BuscarEnFich+0x4e>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1218 <BuscarEnFich+0xb8>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <BuscarCadena@plt>
cmp    $0x0,%rax
je     1213 <BuscarEnFich+0xb3>
mov    -0x8(%rbp),%rsi
mov    -0x124(%rbp),%edx
lea    -0x120(%rbp),%rcx
lea    0xdf4(%rip),%rdi
call   1040 <printf@plt>
jmp    11ae <BuscarEnFich+0x4e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BuscarEnFich>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1214 <BuscarEnFich+0xb4>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fa <BuscarEnFich+0x9a>
mov    $0x1,%ebp
mov    %rsp,%rbx
lea    0xe4f(%rip),%r13
jmp    11d8 <BuscarEnFich+0x78>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
je     11fa <BuscarEnFich+0x9a>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <BuscarCadena@plt>
test   %rax,%rax
je     11c0 <BuscarEnFich+0x60>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1040 <printf@plt>
jmp    11c0 <BuscarEnFich+0x60>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <perror@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"%s[%d]: %s\00"
define void @BuscarEnFich(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @perror(i8* %12)
br label %36
14: ; preds = %2
br label %15
15: ; preds = %32, %14
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = load i32*, i32** %5
%18 = call i32* @fgets(i8* %16, i32 256, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = call i64 @BuscarCadena(i8* %23, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %20
%28 = load i8*, i8** %3
%29 = load i32, i32* %7
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 %29, i8* %30)
br label %32
32: ; preds = %27, %20
br label %15
33: ; preds = %15
%34 = load i32*, i32** %5
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %33, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"%s[%d]: %s\00"
define void @BuscarEnFich(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 256, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %22, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* %0)
br label %24
12: ; preds = %7, %19
%13 = phi i32 [ %14, %19 ], [ 0, %7 ]
%14 = add nuw nsw i32 %13, 1
%15 = call i64 @BuscarCadena(i8* %4, i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %14, i8* %4)
br label %19
19: ; preds = %17, %12
%20 = call i32* @fgets(i8* %4, i32 256, i32* %5)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %12
22: ; preds = %19, %7
%23 = call i32 @fclose(i32* %5)
br label %24
24: ; preds = %22, %10
ret void
}