#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
char *get_message_ID_from_html(char *file_name) {
  char *id_pattern = "<!-- id=";
  char buff[0x1000];
  char *message_id = NULL;
  FILE *f;
  f = fopen(file_name, "r");
  while (fgets(buff, sizeof(buff), f) != NULL) {
    if (strlen(buff) > 0)
      if (strstr(buff, id_pattern) != NULL) {
        message_id = (char *)malloc(sizeof(char) * strlen(buff));
        memcpy(message_id, buff + 9, strlen(buff) - 6 - 9);
        message_id[strlen(buff) - 6 - 9] = '\0';
        break;
      }
  }
  fclose(f);
  return message_id;
}


x86 assembly (clang, -O0):
<get_message_ID_from_html>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x1018(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x1020(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x1020(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12a3 <get_message_ID_from_html+0x133>
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    129e <get_message_ID_from_html+0x12e>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1299 <get_message_ID_from_html+0x129>
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rax
mov    %rax,-0x1038(%rbp)
lea    -0x1010(%rbp),%rax
add    $0x9,%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1038(%rbp),%rdi
mov    -0x1030(%rbp),%rsi
mov    %eax,%edx
sub    $0x6,%edx
sub    $0x9,%edx
call   1060 <memcpy@plt>
mov    -0x1018(%rbp),%rax
mov    %rax,-0x1028(%rbp)
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1028(%rbp),%rax
sub    $0x6,%ecx
sub    $0x9,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12a3 <get_message_ID_from_html+0x133>
jmp    129e <get_message_ID_from_html+0x12e>
jmp    11ac <get_message_ID_from_html+0x3c>
mov    -0x1020(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1018(%rbp),%rax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_message_ID_from_html>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1233 <get_message_ID_from_html+0xc3>
mov    %rsp,%rbx
lea    0xe50(%rip),%r12
xor    %r14d,%r14d
jmp    11d5 <get_message_ID_from_html+0x65>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1236 <get_message_ID_from_html+0xc6>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c0 <get_message_ID_from_html+0x50>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11c0 <get_message_ID_from_html+0x50>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0x9(%rsp),%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    -0xf(%rax),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0xf(%rax,%r14,1)
jmp    1236 <get_message_ID_from_html+0xc6>
xor    %r14d,%r14d
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"<!-- id=\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @get_message_ID_from_html(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [4096 x i8]
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* null, i8** %5
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
br label %9
9: ; preds = %47, %1
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%11 = load i32*, i32** %6
%12 = call i32* @fgets(i8* %10, i32 4096, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %48
14: ; preds = %9
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %47
18: ; preds = %14
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%20 = load i8*, i8** %3
%21 = call i32* @strstr(i8* %19, i8* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %46
23: ; preds = %18
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%33 = getelementptr inbounds i8, i8* %32, i64 9
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = sub nsw i32 %35, 6
%37 = sub nsw i32 %36, 9
%38 = call i32 @memcpy(i8* %31, i8* %33, i32 %37)
%39 = load i8*, i8** %5
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = sub nsw i32 %41, 6
%43 = sub nsw i32 %42, 9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %39, i64 %44
store i8 0, i8* %45
br label %48
46: ; preds = %18
br label %47
47: ; preds = %46, %14
br label %9
48: ; preds = %23, %9
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %5
ret i8* %51
}

LLVM IR (-O2):
@.str = [9 x i8] c"<!-- id=\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @get_message_ID_from_html(i8* nocapture %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32* @fgets(i8* %3, i32 4096, i32* %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %28, label %7
7: ; preds = %1, %25
%8 = call i32 @strlen(i8* %3)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = call i32* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = call i32 @strlen(i8* %3)
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 9
%18 = call i32 @strlen(i8* %3)
%19 = add nsw i32 %18, -15
%20 = call i32 @memcpy(i8* %16, i8* %17, i32 %19)
%21 = call i32 @strlen(i8* %3)
%22 = add nsw i32 %21, -15
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %16, i64 %23
store i8 0, i8* %24
br label %28
25: ; preds = %10, %7
%26 = call i32* @fgets(i8* %3, i32 4096, i32* %4)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %7
28: ; preds = %25, %1, %13
%29 = phi i8* [ %16, %13 ], [ null, %1 ], [ null, %25 ]
%30 = call i32 @fclose(i32* %4)
ret i8* %29
}