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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int check_mbox(const char *path, int *new, int *read, int *unread) {
  char linebuf[(2048)];
  FILE *mbox;
  int linelen;
  unsigned short in_header = 0;
  if ((mbox = fopen(path, "r")) == NULL) {
    fprintf(stderr, "mailcheck: unable to open mbox %s\n", path);
    return -1;
  }
  *new = 0;
  *read = 0;
  *unread = 0;
  while (fgets(linebuf, sizeof(linebuf), mbox)) {
    if (!in_header) {
      if (strncmp(linebuf, "From ", 5) == 0) {
        in_header = 1;
        (*new)++;
      }
    } else {
      if (linebuf[0] == '\n') {
        in_header = 0;
      } else if (strncmp(linebuf, "Status: ", 8) == 0) {
        linelen = strlen(linebuf);
        if (linelen >= 10 && ((linebuf[8] == 'R' && linebuf[9] == 'O') ||
                              (linebuf[8] == 'O' && linebuf[9] == 'R'))) {
          (*new)--;
          (*read)++;
        } else if (linelen >= 9 && linebuf[8] == 'O') {
          (*new)--;
          (*unread)++;
        }
      }
    }
  }
  fclose(mbox);
  return 0;
}


x86 assembly (clang, -O0):
<check_mbox>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movw   $0x0,-0x83e(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x838(%rbp)
cmp    $0x0,%rax
jne    11ca <check_mbox+0x6a>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe49(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136c <check_mbox+0x20c>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x830(%rbp),%rdi
mov    -0x838(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1359 <check_mbox+0x1f9>
cmpw   $0x0,-0x83e(%rbp)
jne    1253 <check_mbox+0xf3>
lea    -0x830(%rbp),%rdi
lea    0xdff(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    124e <check_mbox+0xee>
movw   $0x1,-0x83e(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1354 <check_mbox+0x1f4>
movsbl -0x830(%rbp),%eax
cmp    $0xa,%eax
jne    1271 <check_mbox+0x111>
movw   $0x0,-0x83e(%rbp)
jmp    134f <check_mbox+0x1ef>
lea    -0x830(%rbp),%rdi
lea    0xdac(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    134a <check_mbox+0x1ea>
lea    -0x830(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x83c(%rbp)
cmpl   $0xa,-0x83c(%rbp)
jl     130d <check_mbox+0x1ad>
movsbl -0x828(%rbp),%eax
cmp    $0x52,%eax
jne    12d2 <check_mbox+0x172>
movsbl -0x827(%rbp),%eax
cmp    $0x4f,%eax
je     12f2 <check_mbox+0x192>
movsbl -0x828(%rbp),%eax
cmp    $0x4f,%eax
jne    130d <check_mbox+0x1ad>
movsbl -0x827(%rbp),%eax
cmp    $0x52,%eax
jne    130d <check_mbox+0x1ad>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1345 <check_mbox+0x1e5>
cmpl   $0x9,-0x83c(%rbp)
jl     1340 <check_mbox+0x1e0>
movsbl -0x828(%rbp),%eax
cmp    $0x4f,%eax
jne    1340 <check_mbox+0x1e0>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1345 <check_mbox+0x1e5>
jmp    134a <check_mbox+0x1ea>
jmp    134f <check_mbox+0x1ef>
jmp    1354 <check_mbox+0x1f4>
jmp    11e8 <check_mbox+0x88>
mov    -0x838(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_mbox>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbp
lea    0xe7c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12b5 <check_mbox+0x155>
mov    %rax,%rbx
movl   $0x0,(%r12)
movl   $0x0,(%r15)
mov    %r14,0x8(%rsp)
movl   $0x0,(%r14)
lea    0x10(%rsp),%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12a9 <check_mbox+0x149>
xor    %r14d,%r14d
lea    0xe50(%rip),%r13
lea    0x10(%rsp),%rbp
jmp    11fc <check_mbox+0x9c>
nopl   0x0(%rax)
xor    %r14d,%r14d
mov    %rbp,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12a9 <check_mbox+0x149>
test   %r14w,%r14w
jne    1230 <check_mbox+0xd0>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
mov    %r12,%rdx
test   %rax,%rax
jne    11e0 <check_mbox+0x80>
addl   $0x1,(%rdx)
mov    $0x1,%r14w
jmp    11e3 <check_mbox+0x83>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0xa,0x10(%rsp)
je     11e0 <check_mbox+0x80>
mov    %rbp,%rdi
lea    0xdea(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
mov    $0x1,%r14w
test   %rax,%rax
jne    11e3 <check_mbox+0x83>
mov    %rbp,%rdi
call   1050 <strlen@plt>
movzbl 0x18(%rsp),%ecx
cmp    $0xa,%eax
jl     1288 <check_mbox+0x128>
movzbl 0x19(%rsp),%esi
cmp    $0x52,%cl
jne    127a <check_mbox+0x11a>
mov    %r15,%rdx
cmp    $0x4f,%sil
je     129f <check_mbox+0x13f>
cmp    $0x4f,%cl
jne    1288 <check_mbox+0x128>
mov    %r15,%rdx
cmp    $0x52,%sil
je     129f <check_mbox+0x13f>
cmp    $0x9,%eax
jl     11e3 <check_mbox+0x83>
mov    0x8(%rsp),%rdx
cmp    $0x4f,%cl
jne    11e3 <check_mbox+0x83>
addl   $0xffffffff,(%r12)
jmp    121a <check_mbox+0xba>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    12d2 <check_mbox+0x172>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
mov    %rbp,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"mailcheck: unable to open mbox %s\0A\00"
@.str.2 = [6 x i8] c"From \00"
@.str.3 = [9 x i8] c"Status: \00"
define i32 @check_mbox(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [2048 x i8]
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i16
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i16 0, i16* %13
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %11
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %6
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %19)
store i32 -1, i32* %5
br label %107
21: ; preds = %4
%22 = load i32*, i32** %7
store i32 0, i32* %22
%23 = load i32*, i32** %8
store i32 0, i32* %23
%24 = load i32*, i32** %9
store i32 0, i32* %24
br label %25
25: ; preds = %103, %21
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%27 = load i32*, i32** %11
%28 = call i64 @fgets(i8* %26, i32 2048, i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %104
30: ; preds = %25
%31 = load i16, i16* %13
%32 = icmp ne i16 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %30
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%35 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
store i16 1, i16* %13
%38 = load i32*, i32** %7
%39 = load i32, i32* %38
%40 = add nsw i32 %39, 1
store i32 %40, i32* %38
br label %41
41: ; preds = %37, %33
br label %103
42: ; preds = %30
%43 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 10
br i1 %46, label %47, label %48
47: ; preds = %42
store i16 0, i16* %13
br label %102
48: ; preds = %42
%49 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%50 = call i64 @strncmp(i8* %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %101
52: ; preds = %48
%53 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%54 = call i32 @strlen(i8* %53)
store i32 %54, i32* %12
%55 = load i32, i32* %12
%56 = icmp sge i32 %55, 10
br i1 %56, label %57, label %84
57: ; preds = %52
%58 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 8
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 82
br i1 %61, label %62, label %67
62: ; preds = %57
%63 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 9
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 79
br i1 %66, label %77, label %67
67: ; preds = %62, %57
%68 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 8
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 79
br i1 %71, label %72, label %84
72: ; preds = %67
%73 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 9
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 82
br i1 %76, label %77, label %84
77: ; preds = %72, %62
%78 = load i32*, i32** %7
%79 = load i32, i32* %78
%80 = add nsw i32 %79, -1
store i32 %80, i32* %78
%81 = load i32*, i32** %8
%82 = load i32, i32* %81
%83 = add nsw i32 %82, 1
store i32 %83, i32* %81
br label %100
84: ; preds = %72, %67, %52
%85 = load i32, i32* %12
%86 = icmp sge i32 %85, 9
br i1 %86, label %87, label %99
87: ; preds = %84
%88 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 8
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 79
br i1 %91, label %92, label %99
92: ; preds = %87
%93 = load i32*, i32** %7
%94 = load i32, i32* %93
%95 = add nsw i32 %94, -1
store i32 %95, i32* %93
%96 = load i32*, i32** %9
%97 = load i32, i32* %96
%98 = add nsw i32 %97, 1
store i32 %98, i32* %96
br label %99
99: ; preds = %92, %87, %84
br label %100
100: ; preds = %99, %77
br label %101
101: ; preds = %100, %48
br label %102
102: ; preds = %101, %47
br label %103
103: ; preds = %102, %41
br label %25
104: ; preds = %25
%105 = load i32*, i32** %11
%106 = call i32 @fclose(i32* %105)
store i32 0, i32* %5
br label %107
107: ; preds = %104, %17
%108 = load i32, i32* %5
ret i32 %108
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"mailcheck: unable to open mbox %s\0A\00"
@.str.2 = [6 x i8] c"From \00"
@.str.3 = [9 x i8] c"Status: \00"
define i32 @check_mbox(i8* %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture %3) {
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %61
12: ; preds = %4
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%13 = call i64 @fgets(i8* %6, i32 2048, i32* %7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %59, label %15
15: ; preds = %12
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 8
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 9
br label %18
18: ; preds = %15, %55
%19 = phi i16 [ 0, %15 ], [ %56, %55 ]
%20 = icmp eq i16 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %51, label %55
24: ; preds = %18
%25 = load i8, i8* %6
%26 = icmp eq i8 %25, 10
br i1 %26, label %55, label %27
27: ; preds = %24
%28 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %55
30: ; preds = %27
%31 = call i32 @strlen(i8* %6)
%32 = icmp sgt i32 %31, 9
%33 = load i8, i8* %16
br i1 %32, label %34, label %43
34: ; preds = %30
%35 = icmp eq i8 %33, 82
%36 = load i8, i8* %17
%37 = icmp eq i8 %36, 79
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %47, label %39
39: ; preds = %34
%40 = icmp eq i8 %33, 79
%41 = icmp eq i8 %36, 82
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %47, label %43
43: ; preds = %30, %39
%44 = icmp sgt i32 %31, 8
%45 = icmp eq i8 %33, 79
%46 = select i1 %44, i1 %45, i1 false
br i1 %46, label %47, label %55
47: ; preds = %43, %34, %39
%48 = phi i32* [ %2, %39 ], [ %2, %34 ], [ %3, %43 ]
%49 = load i32, i32* %1
%50 = add nsw i32 %49, -1
store i32 %50, i32* %1
br label %51
51: ; preds = %47, %21
%52 = phi i32* [ %1, %21 ], [ %48, %47 ]
%53 = load i32, i32* %52
%54 = add nsw i32 %53, 1
store i32 %54, i32* %52
br label %55
55: ; preds = %51, %24, %43, %27, %21
%56 = phi i16 [ 1, %43 ], [ 1, %27 ], [ 0, %21 ], [ 0, %24 ], [ 1, %51 ]
%57 = call i64 @fgets(i8* %6, i32 2048, i32* %7)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %18
59: ; preds = %55, %12
%60 = call i32 @fclose(i32* %7)
br label %61
61: ; preds = %59, %9
%62 = phi i32 [ -1, %9 ], [ 0, %59 ]
ret i32 %62
}