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

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
scalar_t__ fgets(char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int vsscanf(char *, char const *, int /*<<< orphan*/);
int vfscanf(FILE *file_pointer, const char *format, va_list arguments_to_read) {
  char buffer[BUFSIZ + 1];
  int count = 0;
  if (fgets(buffer, BUFSIZ, file_pointer) == 0)
    return -1;
  else
    count = vsscanf(buffer, format, arguments_to_read);
  return count;
}


x86 assembly (clang, -O0):
<vfscanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <fgets@plt>
cmp    $0x0,%rax
jne    1198 <vfscanf+0x78>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    11b8 <vfscanf+0x98>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <vsscanf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vfscanf>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rdx
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
lea    0x1(%rsi),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1030 <fgets@plt>
test   %rax,%rax
je     116d <vfscanf+0x4d>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <vsscanf@plt>
jmp    1172 <vfscanf+0x52>
mov    $0xffffffff,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
define i32 @vfscanf(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i32, i32* @BUFSIZ
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %8
%16 = alloca i8, i64 %14
store i64 %14, i64* %9
store i32 0, i32* %10
%17 = load i32, i32* @BUFSIZ
%18 = load i32*, i32** %5
%19 = call i64 @fgets(i8* %16, i32 %17, i32* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %3
store i32 -1, i32* %4
store i32 1, i32* %11
br label %28
22: ; preds = %3
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = call i32 @vsscanf(i8* %16, i8* %23, i32 %24)
store i32 %25, i32* %10
br label %26
26: ; preds = %22
%27 = load i32, i32* %10
store i32 %27, i32* %4
store i32 1, i32* %11
br label %28
28: ; preds = %26, %21
%29 = load i8*, i8** %8
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
define i32 @vfscanf(i32* nocapture %0, i8* %1, i32 %2) {
%4 = load i32, i32* @BUFSIZ
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i64 @fgets(i8* %7, i32 %4, i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = call i32 @vsscanf(i8* %7, i8* %1, i32 %2)
br label %12
12: ; preds = %3, %10
%13 = phi i32 [ %11, %10 ], [ -1, %3 ]
ret i32 %13
}