#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*/ SEEK_CUR;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int fget_struct(FILE *_file, void *_ptr, int size, char *_start_str) {
  int end;
  char *_str;
  end = 0;
  while (!feof(_file) && !end) {
    _str = _start_str;
    while (*_str == fgetc(_file)) {
      _str++;
      if (!*_str) {
        end = 1;
        break;
      }
    }
  }
  if (!end)
    return 0;
  fseek(_file, -strlen(_start_str), SEEK_CUR);
  fread(_ptr, 1, size, _file);
  return 1;
}


x86 assembly (clang, -O0):
<fget_struct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
jne    1193 <fget_struct+0x43>
cmpl   $0x0,-0x2c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11a3 <fget_struct+0x53>
jmp    11fd <fget_struct+0xad>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,%cl
mov    -0x40(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
jne    11f8 <fget_struct+0xa8>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11f3 <fget_struct+0xa3>
movl   $0x1,-0x2c(%rbp)
jmp    11f8 <fget_struct+0xa8>
jmp    11ab <fget_struct+0x5b>
jmp    116e <fget_struct+0x1e>
cmpl   $0x0,-0x2c(%rbp)
jne    1213 <fget_struct+0xc3>
movl   $0x0,-0x4(%rbp)
jmp    1256 <fget_struct+0x106>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
sub    %eax,%esi
mov    0x2db5(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fget_struct>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r13
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1060 <feof@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    1211 <fget_struct+0xc1>
mov    %r15,0x10(%rsp)
mov    %r14d,0xc(%rsp)
lea    0x1(%r13),%r12
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%al
mov    %r12,%r14
nopw   0x0(%rax,%rax,1)
mov    %eax,%r15d
mov    %rbp,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
cmp    %al,%r15b
jne    11be <fget_struct+0x6e>
movzbl (%r14),%eax
add    $0x1,%r14
test   %al,%al
jne    11a0 <fget_struct+0x50>
mov    %rbp,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11cf <fget_struct+0x7f>
cmp    %bl,%r15b
jne    1190 <fget_struct+0x40>
cmp    %bl,%r15b
mov    $0x0,%ebx
jne    1211 <fget_struct+0xc1>
mov    %r13,%rdi
call   1040 <strlen@plt>
neg    %eax
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%edx
mov    %rbp,%rdi
mov    %eax,%esi
call   1070 <fseek@plt>
mov    $0x1,%ebx
mov    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    0xc(%rsp),%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define i32 @fget_struct(i32* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 0, i32* %10
br label %12
12: ; preds = %40, %4
%13 = load i32*, i32** %6
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i32, i32* %10
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br label %20
20: ; preds = %16, %12
%21 = phi i1 [ false, %12 ], [ %19, %16 ]
br i1 %21, label %22, label %41
22: ; preds = %20
%23 = load i8*, i8** %9
store i8* %23, i8** %11
br label %24
24: ; preds = %39, %22
%25 = load i8*, i8** %11
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i32*, i32** %6
%29 = call signext i8 @fgetc(i32* %28)
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %27, %30
br i1 %31, label %32, label %40
32: ; preds = %24
%33 = load i8*, i8** %11
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %11
%35 = load i8*, i8** %11
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %32
store i32 1, i32* %10
br label %40
39: ; preds = %32
br label %24
40: ; preds = %38, %24
br label %12
41: ; preds = %20
%42 = load i32, i32* %10
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %41
store i32 0, i32* %5
br label %56
45: ; preds = %41
%46 = load i32*, i32** %6
%47 = load i8*, i8** %9
%48 = call i32 @strlen(i8* %47)
%49 = sub nsw i32 0, %48
%50 = load i32, i32* @SEEK_CUR
%51 = call i32 @fseek(i32* %46, i32 %49, i32 %50)
%52 = load i8*, i8** %7
%53 = load i32, i32* %8
%54 = load i32*, i32** %6
%55 = call i32 @fread(i8* %52, i32 1, i32 %53, i32* %54)
store i32 1, i32* %5
br label %56
56: ; preds = %45, %44
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define i32 @fget_struct(i32* nocapture %0, i8* nocapture %1, i32 %2, i8* %3) {
%5 = tail call i32 @feof(i32* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %30
7: ; preds = %4, %18
%8 = load i8, i8* %3
br label %9
9: ; preds = %7, %14
%10 = phi i8 [ %16, %14 ], [ %8, %7 ]
%11 = phi i8* [ %15, %14 ], [ %3, %7 ]
%12 = tail call signext i8 @fgetc(i32* %0)
%13 = icmp eq i8 %10, %12
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %9
18: ; preds = %14, %9
%19 = xor i1 %13, true
%20 = tail call i32 @feof(i32* %0)
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i1 %19, i1 false
br i1 %22, label %7, label %23
23: ; preds = %18
br i1 %13, label %24, label %30
24: ; preds = %23
%25 = tail call i32 @strlen(i8* %3)
%26 = sub nsw i32 0, %25
%27 = load i32, i32* @SEEK_CUR
%28 = tail call i32 @fseek(i32* %0, i32 %26, i32 %27)
%29 = tail call i32 @fread(i8* %1, i32 1, i32 %2, i32* %0)
br label %30
30: ; preds = %4, %23, %24
%31 = phi i32 [ 1, %24 ], [ 0, %23 ], [ 0, %4 ]
ret i32 %31
}