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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int is_utf8(unsigned char *, int, char **, int *);
int /*<<< orphan*/ print_utf8_error(char const *, int, int, int, char *, int,
                                    int, char *, int, int, int, int, int);
int is_utf8_readline(FILE *stream, const char *file_path, int quiet,
                     int verbose, int list_only, int invert) {
  char *string = NULL;
  size_t size = 0;
  ssize_t str_length;
  char *message = NULL;
  int lineno = 1;
  int pos = 0;
  int offset = 0;
  int faulty_bytes = 0;
  while ((str_length = getline(&string, &size, stream)) != -1) {
    pos = is_utf8((unsigned char *)string, str_length, &message, &faulty_bytes);
    if (message != NULL) {
      offset += pos;
      print_utf8_error(file_path, lineno, pos, offset, string, str_length, pos,
                       message, faulty_bytes, quiet, verbose, list_only,
                       invert);
      break;
    }
    offset += str_length;
    lineno += 1;
  }
  if (string != NULL)
    free(string);
  return message == NULL ? EXIT_SUCCESS : EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<is_utf8_readline>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %edx,-0x34(%rbp)
mov    %ecx,-0x38(%rbp)
mov    %r8d,-0x3c(%rbp)
mov    %r9d,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x60(%rbp)
movl   $0x1,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <getline@plt>
mov    %eax,-0x54(%rbp)
cmp    $0xffffffff,%eax
je     1254 <is_utf8_readline+0x114>
mov    -0x48(%rbp),%rdi
mov    -0x54(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   1040 <is_utf8@plt>
mov    %eax,-0x68(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     123d <is_utf8_readline+0xfd>
mov    -0x68(%rbp),%eax
add    -0x6c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x64(%rbp),%esi
mov    -0x68(%rbp),%edx
mov    -0x6c(%rbp),%ecx
mov    -0x48(%rbp),%r8
mov    -0x54(%rbp),%r9d
mov    -0x68(%rbp),%r12d
mov    -0x60(%rbp),%r15
mov    -0x70(%rbp),%r14d
mov    -0x34(%rbp),%ebx
mov    -0x38(%rbp),%r11d
mov    -0x3c(%rbp),%r10d
mov    -0x40(%rbp),%eax
mov    %r12d,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14d,0x10(%rsp)
mov    %ebx,0x18(%rsp)
mov    %r11d,0x20(%rsp)
mov    %r10d,0x28(%rsp)
mov    %eax,0x30(%rsp)
call   1060 <print_utf8_error@plt>
jmp    1254 <is_utf8_readline+0x114>
mov    -0x54(%rbp),%eax
add    -0x6c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    119c <is_utf8_readline+0x5c>
cmpq   $0x0,-0x48(%rbp)
je     1268 <is_utf8_readline+0x128>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x60(%rbp)
jne    1284 <is_utf8_readline+0x144>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
jmp    1290 <is_utf8_readline+0x150>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_utf8_readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,0x28(%rsp)
mov    %r8,0x30(%rsp)
mov    %rcx,0x38(%rsp)
mov    %rdx,0x40(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,%rbp
movq   $0x0,(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
mov    %rsp,%rdi
lea    0x18(%rsp),%rsi
mov    %rbp,%rdx
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     123a <is_utf8_readline+0xfa>
mov    %eax,%r14d
mov    $0x1,%r12d
xor    %r15d,%r15d
lea    0x18(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%rdi
mov    %r14d,%esi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1040 <is_utf8@plt>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
jne    11ff <is_utf8_readline+0xbf>
add    %r14d,%r15d
add    $0x1,%r12d
mov    %rsp,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1050 <getline@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    11c0 <is_utf8_readline+0x80>
jmp    123a <is_utf8_readline+0xfa>
add    %eax,%r15d
mov    (%rsp),%r8
mov    0xc(%rsp),%ebp
sub    $0x8,%rsp
mov    0x28(%rsp),%rdi
mov    %r12d,%esi
mov    %eax,%edx
mov    %r15d,%ecx
mov    %r14d,%r9d
push   0x30(%rsp)
push   0x40(%rsp)
push   0x50(%rsp)
push   0x60(%rsp)
push   %rbp
push   %rbx
push   %rax
call   1060 <print_utf8_error@plt>
add    $0x40,%rsp
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1248 <is_utf8_readline+0x108>
call   1030 <free@plt>
cmpq   $0x0,0x10(%rsp)
jne    1259 <is_utf8_readline+0x119>
mov    0x2d81(%rip),%rax
jmp    1260 <is_utf8_readline+0x120>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @is_utf8_readline(i32* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i8* null, i8** %13
store i64 0, i64* %14
store i8* null, i8** %16
store i32 1, i32* %17
store i32 0, i32* %18
store i32 0, i32* %19
store i32 0, i32* %20
br label %21
21: ; preds = %49, %6
%22 = load i32*, i32** %7
%23 = call i32 @getline(i8** %13, i64* %14, i32* %22)
store i32 %23, i32* %15
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %55
25: ; preds = %21
%26 = load i8*, i8** %13
%27 = load i32, i32* %15
%28 = call i32 @is_utf8(i8* %26, i32 %27, i8** %16, i32* %20)
store i32 %28, i32* %18
%29 = load i8*, i8** %16
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %49
31: ; preds = %25
%32 = load i32, i32* %18
%33 = load i32, i32* %19
%34 = add nsw i32 %33, %32
store i32 %34, i32* %19
%35 = load i8*, i8** %8
%36 = load i32, i32* %17
%37 = load i32, i32* %18
%38 = load i32, i32* %19
%39 = load i8*, i8** %13
%40 = load i32, i32* %15
%41 = load i32, i32* %18
%42 = load i8*, i8** %16
%43 = load i32, i32* %20
%44 = load i32, i32* %9
%45 = load i32, i32* %10
%46 = load i32, i32* %11
%47 = load i32, i32* %12
%48 = call i32 @print_utf8_error(i8* %35, i32 %36, i32 %37, i32 %38, i8* %39, i32 %40, i32 %41, i8* %42, i32 %43, i32 %44, i32 %45, i32 %46, i32 %47)
br label %55
49: ; preds = %25
%50 = load i32, i32* %15
%51 = load i32, i32* %19
%52 = add nsw i32 %51, %50
store i32 %52, i32* %19
%53 = load i32, i32* %17
%54 = add nsw i32 %53, 1
store i32 %54, i32* %17
br label %21
55: ; preds = %31, %21
%56 = load i8*, i8** %13
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i8*, i8** %13
%60 = call i32 @free(i8* %59)
br label %61
61: ; preds = %58, %55
%62 = load i8*, i8** %16
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = load i32, i32* @EXIT_SUCCESS
br label %68
66: ; preds = %61
%67 = load i32, i32* @EXIT_FAILURE
br label %68
68: ; preds = %66, %64
%69 = phi i32 [ %65, %64 ], [ %67, %66 ]
ret i32 %69
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @is_utf8_readline(i32* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%12 = bitcast i64* %8 to i8*
store i64 0, i64* %8
%13 = bitcast i8** %9 to i8*
store i8* null, i8** %9
%14 = bitcast i32* %10 to i8*
store i32 0, i32* %10
%15 = call i32 @getline(i8** %7, i64* %8, i32* %0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %35, label %17
17: ; preds = %6, %30
%18 = phi i32 [ %33, %30 ], [ %15, %6 ]
%19 = phi i32 [ %31, %30 ], [ 0, %6 ]
%20 = phi i32 [ %32, %30 ], [ 1, %6 ]
%21 = load i8*, i8** %7
%22 = call i32 @is_utf8(i8* %21, i32 %18, i8** %9, i32* %10)
%23 = load i8*, i8** %9
%24 = icmp eq i8* %23, null
br i1 %24, label %30, label %25
25: ; preds = %17
%26 = add nsw i32 %22, %19
%27 = load i8*, i8** %7
%28 = load i32, i32* %10
%29 = call i32 @print_utf8_error(i8* %1, i32 %20, i32 %22, i32 %26, i8* %27, i32 %18, i32 %22, i8* %23, i32 %28, i32 %2, i32 %3, i32 %4, i32 %5)
br label %35
30: ; preds = %17
%31 = add nsw i32 %18, %19
%32 = add nuw nsw i32 %20, 1
%33 = call i32 @getline(i8** %7, i64* %8, i32* %0)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %17
35: ; preds = %30, %6, %25
%36 = load i8*, i8** %7
%37 = icmp eq i8* %36, null
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @free(i8* %36)
br label %40
40: ; preds = %38, %35
%41 = load i8*, i8** %9
%42 = icmp eq i8* %41, null
%43 = load i32, i32* @EXIT_SUCCESS
%44 = load i32, i32* @EXIT_FAILURE
%45 = select i1 %42, i32 %43, i32 %44
ret i32 %45
}