#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
char *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ count_lines(char *, int /*<<< orphan*/, int, int *, int *);
int /*<<< orphan*/ fopen(char const *, char *);
int fstat(int, struct stat *);
int is_utf8(unsigned char *, int /*<<< orphan*/, char **, int *);
int is_utf8_readline(int /*<<< orphan*/, char const *, int, int, int, int);
char *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_utf8_error(char const *, int, int, int, char *,
                                    int /*<<< orphan*/, int, char *, int, int,
                                    int, int, int);
int is_utf8_mmap(const char *file_path, int quiet, int verbose, int list_only,
                 int invert) {
  char *addr;
  struct stat sb;
  int fd;
  int pos = 0;
  char *message;
  int retval = EXIT_SUCCESS;
  int error_column = 1;
  int error_line = 0;
  int faulty_bytes = 0;
  fd = open(file_path, O_RDONLY);
  if (fd == -1)
    do {
      retval = EXIT_FAILURE;
      perror("open");
      goto err_open;
    } while (0);
  if (fstat(fd, &sb) == -1)
    do {
      retval = EXIT_FAILURE;
      perror("fstat");
      goto err_fstat;
    } while (0);
  addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  if (addr == MAP_FAILED) {
    close(fd);
    return is_utf8_readline(fopen(file_path, "r"), file_path, quiet, verbose,
                            list_only, invert);
  }
  pos = is_utf8((unsigned char *)addr, sb.st_size, &message, &faulty_bytes);
  if (message != NULL)
    count_lines(addr, sb.st_size, pos, &error_line, &error_column);
  print_utf8_error(file_path, error_line, error_column, pos, addr, sb.st_size,
                   pos, message, faulty_bytes, quiet, verbose, list_only,
                   invert);
  if (message != NULL)
    retval = EXIT_FAILURE;
  munmap(addr, sb.st_size);
err_fstat:
  close(fd);
err_open:
  return retval;
}


x86 assembly (clang, -O0):
<is_utf8_mmap>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %rdi,-0x30(%rbp)
mov    %esi,-0x34(%rbp)
mov    %edx,-0x38(%rbp)
mov    %ecx,-0x3c(%rbp)
mov    %r8d,-0x40(%rbp)
movl   $0x0,-0x58(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
movl   $0x1,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    123c <is_utf8_mmap+0x8c>
jmp    121f <is_utf8_mmap+0x6f>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
lea    0xdce(%rip),%rdi
call   10b0 <perror@plt>
jmp    13a1 <is_utf8_mmap+0x1f1>
mov    -0x54(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   10d0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1273 <is_utf8_mmap+0xc3>
jmp    1256 <is_utf8_mmap+0xa6>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
lea    0xd9c(%rip),%rdi
call   10b0 <perror@plt>
jmp    1399 <is_utf8_mmap+0x1e9>
mov    -0x50(%rbp),%esi
mov    0x2d7b(%rip),%rax
mov    (%rax),%edx
mov    0x2d3a(%rip),%rax
mov    (%rax),%ecx
mov    -0x54(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x2d11(%rip),%rcx
cmp    (%rcx),%rax
jne    12e9 <is_utf8_mmap+0x139>
mov    -0x54(%rbp),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%rdi
lea    0xd48(%rip),%rsi
call   10a0 <fopen@plt>
mov    %eax,%edi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
mov    -0x40(%rbp),%r9d
call   1060 <is_utf8_readline@plt>
mov    %eax,-0x24(%rbp)
jmp    13a7 <is_utf8_mmap+0x1f7>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   1030 <is_utf8@plt>
mov    %eax,-0x58(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     1322 <is_utf8_mmap+0x172>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%esi
mov    -0x58(%rbp),%edx
lea    -0x6c(%rbp),%rcx
lea    -0x68(%rbp),%r8
call   1070 <count_lines@plt>
mov    -0x30(%rbp),%rdi
mov    -0x6c(%rbp),%esi
mov    -0x68(%rbp),%edx
mov    -0x58(%rbp),%ecx
mov    -0x48(%rbp),%r8
mov    -0x50(%rbp),%r9d
mov    -0x58(%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   10c0 <print_utf8_error@plt>
cmpq   $0x0,-0x60(%rbp)
je     138d <is_utf8_mmap+0x1dd>
mov    0x2c48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%esi
call   1080 <munmap@plt>
mov    -0x54(%rbp),%edi
call   1050 <close@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_utf8_mmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8d,%r12d
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %esi,%ebx
mov    0x2df9(%rip),%rax
mov    (%rax),%r13d
movl   $0x1,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
mov    0x2def(%rip),%rax
mov    (%rax),%esi
mov    %rdi,0x40(%rsp)
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1375 <is_utf8_mmap+0x1c5>
mov    %eax,%r14d
lea    0x18(%rsp),%rsi
mov    %eax,%edi
call   10d0 <fstat@plt>
cmp    $0xffffffff,%eax
je     138c <is_utf8_mmap+0x1dc>
mov    %r12,0x20(%rsp)
mov    %r15,0x28(%rsp)
mov    %rbp,0x30(%rsp)
mov    %rbx,0x38(%rsp)
mov    0x18(%rsp),%r15d
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
mov    0x2d79(%rip),%rax
mov    (%rax),%ecx
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r15d,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r12
mov    0x2d53(%rip),%rax
cmp    (%rax),%r12
je     12b6 <is_utf8_mmap+0x106>
mov    %r13d,0x1c(%rsp)
lea    0x10(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %r12,%rdi
mov    %r15d,%esi
call   1030 <is_utf8@plt>
mov    %eax,%r13d
cmpq   $0x0,0x10(%rsp)
je     12fe <is_utf8_mmap+0x14e>
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r13d,%edx
call   1070 <count_lines@plt>
mov    0x8(%rsp),%ebx
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%r10
jmp    1306 <is_utf8_mmap+0x156>
mov    %r14d,%edi
call   1050 <close@plt>
lea    0xd46(%rip),%rsi
mov    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    0x38(%rsp),%rdx
mov    0x30(%rsp),%rcx
mov    0x28(%rsp),%r8
mov    0x20(%rsp),%r9
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <is_utf8_readline@plt>
mov    $0x1,%edx
xor    %r10d,%r10d
mov    0x4(%rsp),%eax
sub    $0x8,%rsp
mov    0x48(%rsp),%rdi
mov    %ebx,%esi
mov    %r13d,%ecx
mov    %r12,%r8
mov    %r15d,%r9d
push   0x28(%rsp)
push   0x38(%rsp)
push   0x48(%rsp)
push   0x58(%rsp)
push   %rax
push   %r10
push   %r13
call   10c0 <print_utf8_error@plt>
add    $0x40,%rsp
cmpq   $0x0,0x10(%rsp)
mov    0x1c(%rsp),%ebx
je     1351 <is_utf8_mmap+0x1a1>
mov    0x2c81(%rip),%rax
mov    (%rax),%ebx
mov    %r12,%rdi
mov    %r15d,%esi
call   1080 <munmap@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c54(%rip),%rax
mov    (%rax),%ebx
lea    0xc7b(%rip),%rdi
call   10b0 <perror@plt>
jmp    1364 <is_utf8_mmap+0x1b4>
mov    0x2c3d(%rip),%rax
mov    (%rax),%ebx
lea    0xc69(%rip),%rdi
call   10b0 <perror@plt>
jmp    135c <is_utf8_mmap+0x1ac>

LLVM IR (-O0):
%struct.stat = type { i32 }
@EXIT_SUCCESS = global i32 0
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [6 x i8] c"fstat\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [2 x i8] c"r\00"
define i32 @is_utf8_mmap(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca %struct.stat
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 0, i32* %15
%21 = load i32, i32* @EXIT_SUCCESS
store i32 %21, i32* %17
store i32 1, i32* %18
store i32 0, i32* %19
store i32 0, i32* %20
%22 = load i8*, i8** %7
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %14
%25 = load i32, i32* %14
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %32
27: ; preds = %5
br label %28
28: ; preds = %27
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %17
%30 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %103
31: ; No predecessors!
br label %32
32: ; preds = %31, %5
%33 = load i32, i32* %14
%34 = call i32 @fstat(i32 %33, %struct.stat* %13)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %41
36: ; preds = %32
br label %37
37: ; preds = %36
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %17
%39 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %100
40: ; No predecessors!
br label %41
41: ; preds = %40, %32
%42 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%43 = load i32, i32* %42
%44 = load i32, i32* @PROT_READ
%45 = load i32, i32* @MAP_PRIVATE
%46 = load i32, i32* %14
%47 = call i8* @mmap(i32* null, i32 %43, i32 %44, i32 %45, i32 %46, i32 0)
store i8* %47, i8** %12
%48 = load i8*, i8** %12
%49 = load i8*, i8** @MAP_FAILED
%50 = icmp eq i8* %48, %49
br i1 %50, label %51, label %62
51: ; preds = %41
%52 = load i32, i32* %14
%53 = call i32 @close(i32 %52)
%54 = load i8*, i8** %7
%55 = call i32 @fopen(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%56 = load i8*, i8** %7
%57 = load i32, i32* %8
%58 = load i32, i32* %9
%59 = load i32, i32* %10
%60 = load i32, i32* %11
%61 = call i32 @is_utf8_readline(i32 %55, i8* %56, i32 %57, i32 %58, i32 %59, i32 %60)
store i32 %61, i32* %6
br label %105
62: ; preds = %41
%63 = load i8*, i8** %12
%64 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i32 @is_utf8(i8* %63, i32 %65, i8** %16, i32* %20)
store i32 %66, i32* %15
%67 = load i8*, i8** %16
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %75
69: ; preds = %62
%70 = load i8*, i8** %12
%71 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%72 = load i32, i32* %71
%73 = load i32, i32* %15
%74 = call i32 @count_lines(i8* %70, i32 %72, i32 %73, i32* %19, i32* %18)
br label %75
75: ; preds = %69, %62
%76 = load i8*, i8** %7
%77 = load i32, i32* %19
%78 = load i32, i32* %18
%79 = load i32, i32* %15
%80 = load i8*, i8** %12
%81 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%82 = load i32, i32* %81
%83 = load i32, i32* %15
%84 = load i8*, i8** %16
%85 = load i32, i32* %20
%86 = load i32, i32* %8
%87 = load i32, i32* %9
%88 = load i32, i32* %10
%89 = load i32, i32* %11
%90 = call i32 @print_utf8_error(i8* %76, i32 %77, i32 %78, i32 %79, i8* %80, i32 %82, i32 %83, i8* %84, i32 %85, i32 %86, i32 %87, i32 %88, i32 %89)
%91 = load i8*, i8** %16
%92 = icmp ne i8* %91, null
br i1 %92, label %93, label %95
93: ; preds = %75
%94 = load i32, i32* @EXIT_FAILURE
store i32 %94, i32* %17
br label %95
95: ; preds = %93, %75
%96 = load i8*, i8** %12
%97 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%98 = load i32, i32* %97
%99 = call i32 @munmap(i8* %96, i32 %98)
br label %100
100: ; preds = %95, %37
%101 = load i32, i32* %14
%102 = call i32 @close(i32 %101)
br label %103
103: ; preds = %100, %28
%104 = load i32, i32* %17
store i32 %104, i32* %6
br label %105
105: ; preds = %103, %51
%106 = load i32, i32* %6
ret i32 %106
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EXIT_SUCCESS = global i32 0
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [6 x i8] c"fstat\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [2 x i8] c"r\00"
define i32 @is_utf8_mmap(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = bitcast %struct.stat* %6 to i8*
%12 = bitcast i8** %7 to i8*
%13 = load i32, i32* @EXIT_SUCCESS
%14 = bitcast i32* %8 to i8*
store i32 1, i32* %8
%15 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%16 = bitcast i32* %10 to i8*
store i32 0, i32* %10
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* %0, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %5
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %64
23: ; preds = %5
%24 = call i32 @fstat(i32 %18, %struct.stat* %6)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %61
29: ; preds = %23
%30 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%31 = load i32, i32* %30
%32 = load i32, i32* @PROT_READ
%33 = load i32, i32* @MAP_PRIVATE
%34 = tail call i8* @mmap(i32* null, i32 %31, i32 %32, i32 %33, i32 %18, i32 0)
%35 = load i8*, i8** @MAP_FAILED
%36 = icmp eq i8* %34, %35
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = tail call i32 @close(i32 %18)
%39 = tail call i32 @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = tail call i32 @is_utf8_readline(i32 %39, i8* %0, i32 %1, i32 %2, i32 %3, i32 %4)
br label %64
41: ; preds = %29
%42 = call i32 @is_utf8(i8* %34, i32 %31, i8** %7, i32* %10)
%43 = load i8*, i8** %7
%44 = icmp eq i8* %43, null
br i1 %44, label %50, label %45
45: ; preds = %41
%46 = call i32 @count_lines(i8* %34, i32 %31, i32 %42, i32* %9, i32* %8)
%47 = load i32, i32* %9
%48 = load i32, i32* %8
%49 = load i8*, i8** %7
br label %50
50: ; preds = %45, %41
%51 = phi i8* [ %49, %45 ], [ null, %41 ]
%52 = phi i32 [ %48, %45 ], [ 1, %41 ]
%53 = phi i32 [ %47, %45 ], [ 0, %41 ]
%54 = load i32, i32* %10
%55 = call i32 @print_utf8_error(i8* %0, i32 %53, i32 %52, i32 %42, i8* %34, i32 %31, i32 %42, i8* %51, i32 %54, i32 %1, i32 %2, i32 %3, i32 %4)
%56 = load i8*, i8** %7
%57 = icmp eq i8* %56, null
%58 = load i32, i32* @EXIT_FAILURE
%59 = select i1 %57, i32 %13, i32 %58
%60 = call i32 @munmap(i8* %34, i32 %31)
br label %61
61: ; preds = %50, %26
%62 = phi i32 [ %27, %26 ], [ %59, %50 ]
%63 = call i32 @close(i32 %18)
br label %64
64: ; preds = %20, %61, %37
%65 = phi i32 [ %40, %37 ], [ %21, %20 ], [ %62, %61 ]
ret i32 %65
}