#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*/ linha;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
void carregar(char *argv[]) {
  char temp, linha[8000];
  int id_texto, r, j = 0;
  if ((id_texto = open(argv[1], O_RDONLY)) == -1) {
    perror("open");
    exit(1);
  }
  while ((r = read(id_texto, &temp, sizeof(char))) != 0) {
    if (temp != '\n') {
      linha[j] = temp;
      j++;
    } else {
      if (strstr(linha, argv[2]) != NULL)
        printf("%s\n", linha);
      memset(linha, 0, sizeof(linha));
      j = 0;
    }
  }
}


x86 assembly (clang, -O0):
<carregar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f60,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1f5c(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1f54(%rbp)
cmp    $0xffffffff,%eax
jne    11c4 <carregar+0x54>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11c9 <carregar+0x59>
mov    -0x1f54(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x1f58(%rbp)
cmp    $0x0,%eax
je     1271 <carregar+0x101>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     121e <carregar+0xae>
mov    -0x9(%rbp),%cl
movslq -0x1f5c(%rbp),%rax
mov    %cl,-0x1f50(%rbp,%rax,1)
mov    -0x1f5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f5c(%rbp)
jmp    126c <carregar+0xfc>
lea    -0x1f50(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     124f <carregar+0xdf>
lea    -0x1f50(%rbp),%rsi
lea    0xdbb(%rip),%rdi
call   1030 <printf@plt>
lea    -0x1f50(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f40,%edx
call   1040 <memset@plt>
movl   $0x0,-0x1f5c(%rbp)
jmp    11c9 <carregar+0x59>
add    $0x1f60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<carregar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f58,%rsp
mov    %rdi,%r14
mov    0x8(%rdi),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1237 <carregar+0xc7>
mov    %eax,%ebp
lea    0xf(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1225 <carregar+0xb5>
xor    %ebx,%ebx
lea    0x10(%rsp),%r13
lea    0xe41(%rip),%r15
lea    0xf(%rsp),%r12
jmp    11ed <carregar+0x7d>
nopl   0x0(%rax,%rax,1)
movslq %ebx,%rbx
mov    %al,0x10(%rsp,%rbx,1)
add    $0x1,%ebx
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1225 <carregar+0xb5>
movzbl 0xf(%rsp),%eax
cmp    $0xa,%al
jne    11d0 <carregar+0x60>
mov    0x10(%r14),%rsi
mov    %r13,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     1212 <carregar+0xa2>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x1f40,%edx
call   1040 <memset@plt>
jmp    11da <carregar+0x6a>
add    $0x1f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc2(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @carregar(i8** %0) {
%2 = alloca i8**
%3 = alloca i8
%4 = alloca [8000 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %7
%8 = load i8**, i8*** %2
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
br label %18
18: ; preds = %46, %17
%19 = load i32, i32* %5
%20 = call i32 @read(i32 %19, i8* %3, i32 1)
store i32 %20, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %47
22: ; preds = %18
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = load i8, i8* %3
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [8000 x i8], [8000 x i8]* %4, i64 0, i64 %29
store i8 %27, i8* %30
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %46
33: ; preds = %22
%34 = getelementptr inbounds [8000 x i8], [8000 x i8]* %4, i64 0, i64 0
%35 = load i8**, i8*** %2
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32* @strstr(i8* %34, i8* %37)
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = getelementptr inbounds [8000 x i8], [8000 x i8]* %4, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %33
%44 = getelementptr inbounds [8000 x i8], [8000 x i8]* %4, i64 0, i64 0
%45 = call i32 @memset(i8* %44, i32 0, i32 8000)
store i32 0, i32* %7
br label %46
46: ; preds = %43, %26
br label %18
47: ; preds = %18
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @carregar(i8** nocapture %0) {
%2 = alloca i8
%3 = alloca [8000 x i8]
%4 = getelementptr inbounds [8000 x i8], [8000 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %0, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = call i32 @read(i32 %8, i8* %2, i32 1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %38, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8*, i8** %0, i64 2
br label %18
15: ; preds = %1
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %13, %34
%19 = phi i32 [ 0, %13 ], [ %35, %34 ]
%20 = load i8, i8* %2
%21 = icmp eq i8 %20, 10
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = sext i32 %19 to i64
%24 = getelementptr inbounds [8000 x i8], [8000 x i8]* %3, i64 0, i64 %23
store i8 %20, i8* %24
%25 = add nsw i32 %19, 1
br label %34
26: ; preds = %18
%27 = load i8*, i8** %14
%28 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %32
32: ; preds = %30, %26
%33 = call i32 @memset(i8* %4, i32 0, i32 8000)
br label %34
34: ; preds = %32, %22
%35 = phi i32 [ %25, %22 ], [ 0, %32 ]
%36 = call i32 @read(i32 %8, i8* %2, i32 1)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %18
38: ; preds = %34, %10
ret void
}