#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int esta_en_fich(char *palabra, char *fichero) {
  int fd = 0;
  char buff[strlen(palabra)];
  fd = open(fichero, O_RDONLY);
  if (fd < 0) {
    err(1, "%s", fichero);
  }
  read(fd, buff, strlen(palabra));
  close(fd);
  if (!strncmp(buff, palabra, strlen(palabra))) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<esta_en_fich>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d9 <esta_en_fich+0x79>
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xe2c(%rip),%rsi
call   1070 <err@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1060 <read@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    123a <esta_en_fich+0xda>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1248 <esta_en_fich+0xe8>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<esta_en_fich>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1080 <open@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    11b5 <esta_en_fich+0x55>
lea    0xe58(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
call   1070 <err@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <read@plt>
mov    %r12d,%edi
call   1050 <close@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @esta_en_fich(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
%15 = load i8*, i8** %5
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i8*, i8** %5
%22 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %2
%24 = load i32, i32* %6
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @read(i32 %24, i8* %14, i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
%30 = load i8*, i8** %4
%31 = load i8*, i8** %4
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @strncmp(i8* %14, i8* %30, i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %23
store i32 1, i32* %3
store i32 1, i32* %9
br label %37
36: ; preds = %23
store i32 0, i32* %3
store i32 1, i32* %9
br label %37
37: ; preds = %36, %35
%38 = load i8*, i8** %7
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @esta_en_fich(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %1, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %11
11: ; preds = %9, %2
%12 = tail call i32 @strlen(i8* %0)
%13 = call i32 @read(i32 %7, i8* %5, i32 %12)
%14 = tail call i32 @close(i32 %7)
%15 = tail call i32 @strlen(i8* %0)
%16 = call i32 @strncmp(i8* %5, i8* %0, i32 %15)
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i32
ret i32 %18
}