#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int sscanf(char *, char *, char *);
int strlen(char const *);
char *get_header_field_from_file(FILE *input_file, const char *prefix,
                                 char *buffer) {
  int flag_scanf = 0;
  char *str = NULL;
  char *prefix_str = NULL;
  str = (char *)malloc(100 * sizeof(char));
  prefix_str = (char *)malloc((strlen(prefix) + 3) * sizeof(char));
  memset(str, '\0', 100 * sizeof(char));
  memset(prefix_str, '\0', (strlen(prefix) + 3) * sizeof(char));
  sprintf(prefix_str, "%s%%s", prefix);
  rewind(input_file);
  while (fgets(str, 100, input_file)) {
    flag_scanf = sscanf(str, prefix_str, buffer);
    if (flag_scanf != 0) {
      break;
    }
  }
  rewind(input_file);
}


x86 assembly (clang, -O0):
<get_header_field_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x3,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    $0x3,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdf4(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     125e <get_header_field_from_file+0xee>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1259 <get_header_field_from_file+0xe9>
jmp    125e <get_header_field_from_file+0xee>
jmp    121a <get_header_field_from_file+0xaa>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_header_field_from_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    0x3(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    0x3(%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe33(%rip),%rsi
mov    %r12,%rdi
mov    %r13,%rdx
call   1090 <sprintf@plt>
mov    %r15,%rdi
call   1040 <rewind@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1207 <get_header_field_from_file+0x97>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1080 <sscanf@plt>
test   %eax,%eax
je     11e0 <get_header_field_from_file+0x70>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <rewind@plt>

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

LLVM IR (-O2):
@.str = [6 x i8] c"%s%%s\00"
define noalias i8* @get_header_field_from_file(i32* nocapture %0, i8* %1, i8* %2) {
%4 = tail call i64 @malloc(i32 100)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strlen(i8* %1)
%7 = add nsw i32 %6, 3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @memset(i8* %5, i8 signext 0, i32 100)
%11 = tail call i32 @strlen(i8* %1)
%12 = add nsw i32 %11, 3
%13 = tail call i32 @memset(i8* %9, i8 signext 0, i32 %12)
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1)
%15 = tail call i32 @rewind(i32* %0)
br label %16
16: ; preds = %19, %3
%17 = tail call i64 @fgets(i8* %5, i32 100, i32* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = tail call i32 @sscanf(i8* %5, i8* %9, i8* %2)
%21 = icmp eq i32 %20, 0
br i1 %21, label %16, label %22
22: ; preds = %19, %16
%23 = tail call i32 @rewind(i32* %0)
ret i8* undef
}