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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
char *get_element_from_html(char *file_name, char *element_name) {
  char *element_pattern = NULL;
  char buff[0x1000];
  char *element_val = NULL;
  FILE *f;
  f = fopen(file_name, "r");
  if (!f)
    return NULL;
  element_pattern = (char *)malloc(
      sizeof(char) * (strlen(element_name) + strlen("<!-- ") + 2));
  sprintf(element_pattern, "<!-- %s", element_name);
  while (fgets(buff, sizeof(buff), f) != NULL) {
    if (strlen(buff) > 0)
      if (strstr(buff, element_pattern) != NULL) {
        int pattern_offset = strlen(element_pattern) + 2;
        element_val = (char *)malloc(sizeof(char) * strlen(buff));
        memcpy(element_val, buff + pattern_offset,
               strlen(buff) - 6 - pattern_offset);
        element_val[strlen(buff) - 6 - pattern_offset] = '\0';
        break;
      }
  }
  fclose(f);
  free(element_pattern);
  return element_val;
}


x86 assembly (clang, -O0):
<get_element_from_html>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x1028(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x1030(%rbp)
cmpq   $0x0,-0x1030(%rbp)
jne    11e8 <get_element_from_html+0x58>
movq   $0x0,-0x8(%rbp)
jmp    136a <get_element_from_html+0x1da>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1038(%rbp)
lea    0xe04(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x1038(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdd8(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x1030(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     134a <get_element_from_html+0x1ba>
lea    -0x1020(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jle    1345 <get_element_from_html+0x1b5>
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     1340 <get_element_from_html+0x1b0>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x1034(%rbp)
lea    -0x1020(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rax
mov    %rax,-0x1050(%rbp)
lea    -0x1020(%rbp),%rax
movslq -0x1034(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x1048(%rbp)
lea    -0x1020(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1050(%rbp),%rdi
mov    -0x1048(%rbp),%rsi
mov    %eax,%edx
sub    $0x6,%edx
sub    -0x1034(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x1028(%rbp),%rax
mov    %rax,-0x1040(%rbp)
lea    -0x1020(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x1040(%rbp),%rax
sub    $0x6,%ecx
sub    -0x1034(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    134a <get_element_from_html+0x1ba>
jmp    1345 <get_element_from_html+0x1b5>
jmp    1235 <get_element_from_html+0xa5>
mov    -0x1030(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1028(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_element_from_html>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%r15
lea    0xe55(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12b7 <get_element_from_html+0x127>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0xe35(%rip),%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xe21(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   10a0 <sprintf@plt>
lea    0x10(%rsp),%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12bc <get_element_from_html+0x12c>
lea    0x10(%rsp),%rbx
xor    %r15d,%r15d
jmp    1239 <get_element_from_html+0xa9>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12bf <get_element_from_html+0x12f>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1220 <get_element_from_html+0x90>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     1220 <get_element_from_html+0x90>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%rax
add    $0x2,%rax
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0xfffffff8,%r13d
sub    %ebp,%r13d
lea    (%rax,%r13,1),%edx
mov    %r15,%rdi
mov    0x8(%rsp),%rsi
call   1070 <memcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %r13d,%eax
cltq
movb   $0x0,(%r15,%rax,1)
jmp    12bf <get_element_from_html+0x12f>
xor    %r15d,%r15d
jmp    12cf <get_element_from_html+0x13f>
xor    %r15d,%r15d
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"<!-- \00"
@.str.2 = [8 x i8] c"<!-- %s\00"
define i8* @get_element_from_html(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [4096 x i8]
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i8* null, i8** %8
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = icmp ne i32* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i8* null, i8** %3
br label %82
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = add nsw i32 %18, %19
%21 = add nsw i32 %20, 2
%22 = sext i32 %21 to i64
%23 = mul i64 1, %22
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = load i8*, i8** %5
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %75, %16
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%32 = load i32*, i32** %9
%33 = call i32* @fgets(i8* %31, i32 4096, i32* %32)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %76
35: ; preds = %30
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %75
39: ; preds = %35
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%41 = load i8*, i8** %6
%42 = call i32* @strstr(i8* %40, i8* %41)
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %74
44: ; preds = %39
%45 = load i8*, i8** %6
%46 = call i32 @strlen(i8* %45)
%47 = add nsw i32 %46, 2
store i32 %47, i32* %10
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = sext i32 %49 to i64
%51 = mul i64 1, %50
%52 = trunc i64 %51 to i32
%53 = call i64 @malloc(i32 %52)
%54 = inttoptr i64 %53 to i8*
store i8* %54, i8** %8
%55 = load i8*, i8** %8
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = sub nsw i32 %61, 6
%63 = load i32, i32* %10
%64 = sub nsw i32 %62, %63
%65 = call i32 @memcpy(i8* %55, i8* %59, i32 %64)
%66 = load i8*, i8** %8
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%68 = call i32 @strlen(i8* %67)
%69 = sub nsw i32 %68, 6
%70 = load i32, i32* %10
%71 = sub nsw i32 %69, %70
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %66, i64 %72
store i8 0, i8* %73
br label %76
74: ; preds = %39
br label %75
75: ; preds = %74, %35
br label %30
76: ; preds = %44, %30
%77 = load i32*, i32** %9
%78 = call i32 @fclose(i32* %77)
%79 = load i8*, i8** %6
%80 = call i32 @free(i8* %79)
%81 = load i8*, i8** %8
store i8* %81, i8** %3
br label %82
82: ; preds = %76, %15
%83 = load i8*, i8** %3
ret i8* %83
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"<!-- \00"
@.str.2 = [8 x i8] c"<!-- %s\00"
define i8* @get_element_from_html(i8* nocapture %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 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 %46, label %7
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = add i32 %8, 2
%11 = add i32 %10, %9
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%15 = call i32* @fgets(i8* %4, i32 4096, i32* %5)
%16 = icmp eq i32* %15, null
br i1 %16, label %42, label %17
17: ; preds = %7, %39
%18 = call i32 @strlen(i8* %4)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %39
20: ; preds = %17
%21 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %13)
%22 = icmp eq i32* %21, null
br i1 %22, label %39, label %23
23: ; preds = %20
%24 = call i32 @strlen(i8* %13)
%25 = add nsw i32 %24, 2
%26 = call i32 @strlen(i8* %4)
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = sext i32 %25 to i64
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %29
%31 = call i32 @strlen(i8* %4)
%32 = sub i32 -8, %24
%33 = add i32 %32, %31
%34 = call i32 @memcpy(i8* %28, i8* %30, i32 %33)
%35 = call i32 @strlen(i8* %4)
%36 = add i32 %32, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %28, i64 %37
store i8 0, i8* %38
br label %42
39: ; preds = %20, %17
%40 = call i32* @fgets(i8* %4, i32 4096, i32* %5)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %17
42: ; preds = %39, %7, %23
%43 = phi i8* [ %28, %23 ], [ null, %7 ], [ null, %39 ]
%44 = call i32 @fclose(i32* %5)
%45 = call i32 @free(i8* %13)
br label %46
46: ; preds = %2, %42
%47 = phi i8* [ %43, %42 ], [ null, %2 ]
ret i8* %47
}