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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int elem_in_contents(char *path, char *contents_path) {
  int number_of_line = 0;
  char line[300];
  char aux_path[256];
  sprintf(aux_path, "%s\n", path);
  FILE *file = fopen(contents_path, "r");
  while (fgets(line, 300, file)) {
    if (!strcmp(aux_path, line)) {
      fclose(file);
      return number_of_line;
    }
    number_of_line++;
  }
  fclose(file);
  return -1;
}


x86 assembly (clang, -O0):
<elem_in_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x250(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x258(%rbp)
lea    -0x150(%rbp),%rdi
mov    -0x258(%rbp),%rdx
mov    $0x12c,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11fb <elem_in_contents+0xab>
lea    -0x250(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ed <elem_in_contents+0x9d>
mov    -0x258(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120e <elem_in_contents+0xbe>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1198 <elem_in_contents+0x48>
mov    -0x258(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elem_in_contents>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x230,%rsp
mov    %rsi,%rbx
mov    %rdi,%rdx
lea    0xe94(%rip),%rsi
mov    %rsp,%rdi
call   1070 <sprintf@plt>
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%r12
lea    0x100(%rsp),%rdi
mov    $0x12c,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11ec <elem_in_contents+0x9c>
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0x100(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11e9 <elem_in_contents+0x99>
add    $0x1,%ebx
mov    %rbp,%rdi
mov    $0x12c,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11c0 <elem_in_contents+0x70>
jmp    11ec <elem_in_contents+0x9c>
mov    %ebx,%r14d
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
add    $0x230,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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