#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 */

/* Variables and functions */
int /*<<< orphan*/ fatal_error(char *, char *);
int /*<<< orphan*/ uint4(unsigned char *);
int uint8(unsigned char *);
int parse_next_msg(unsigned char **sec) {
  unsigned char *p, *end_of_msg;
  end_of_msg = sec[0] + uint8(&(sec[0][8]));
  p = sec[7];
  if (p[4] != 7) {
    fatal_error("parse_next_msg: parsing error", "");
  }
  p += uint4(p);
  if (p > end_of_msg)
    fatal_error("bad grib fill", "");
  while (p < sec[8]) {
    sec[p[4]] = p;
    if (p[4] == 6) {
      if (p[5] == 0) {
        sec[9] = p;
      } else if (p[5] >= 1 && p[5] <= 253) {
        fatal_error("parse_next_msg: predefined bitmaps are not handled", "");
      } else if (p[5] == 254) {
        if ((sec[6] = sec[9]) == NULL) {
          fatal_error("parse_1st_msg: illegal grib msg, bitmap not defined "
                      "code, table 6.0=254",
                      "");
        }
      }
    }
    if (p[4] == 7) {
      return 0;
    }
    p += uint4(p);
    if (p > end_of_msg)
      fatal_error("bad grib fill", "");
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_next_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
add    $0x8,%rdi
call   1030 <uint8@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x38(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0x7,%eax
je     1197 <parse_next_msg+0x67>
lea    0xe75(%rip),%rdi
lea    0xf14(%rip),%rsi
call   1050 <fatal_error@plt>
mov    -0x18(%rbp),%rdi
call   1040 <uint4@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11d1 <parse_next_msg+0xa1>
lea    0xe59(%rip),%rdi
lea    0xeda(%rip),%rsi
call   1050 <fatal_error@plt>
jmp    11d6 <parse_next_msg+0xa6>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x40(%rcx),%rax
jae    131b <parse_next_msg+0x1eb>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl 0x4(%rcx),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0x6,%eax
jne    12bf <parse_next_msg+0x18f>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0x0,%eax
jne    122f <parse_next_msg+0xff>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x48(%rax)
jmp    12ba <parse_next_msg+0x18a>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0x1,%eax
jl     126b <parse_next_msg+0x13b>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0xfd,%eax
jg     126b <parse_next_msg+0x13b>
lea    0xdd2(%rip),%rdi
lea    0xe45(%rip),%rsi
call   1050 <fatal_error@plt>
jmp    12b5 <parse_next_msg+0x185>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0xfe,%eax
jne    12b0 <parse_next_msg+0x180>
mov    -0x10(%rbp),%rax
mov    0x48(%rax),%rax
mov    -0x10(%rbp),%rcx
mov    %rax,0x30(%rcx)
cmp    $0x0,%rax
jne    12ab <parse_next_msg+0x17b>
lea    0xdc0(%rip),%rdi
lea    0xe00(%rip),%rsi
call   1050 <fatal_error@plt>
jmp    12b0 <parse_next_msg+0x180>
jmp    12b5 <parse_next_msg+0x185>
jmp    12ba <parse_next_msg+0x18a>
jmp    12bf <parse_next_msg+0x18f>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0x7,%eax
jne    12dc <parse_next_msg+0x1ac>
movl   $0x0,-0x4(%rbp)
jmp    1322 <parse_next_msg+0x1f2>
mov    -0x18(%rbp),%rdi
call   1040 <uint4@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    1316 <parse_next_msg+0x1e6>
lea    0xd14(%rip),%rdi
lea    0xd95(%rip),%rsi
call   1050 <fatal_error@plt>
jmp    11d6 <parse_next_msg+0xa6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_next_msg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rbx
lea    0x8(%rbx),%rdi
call   1030 <uint8@plt>
movslq %eax,%r15
add    %rbx,%r15
mov    0x38(%r14),%rbp
cmpb   $0x7,0x4(%rbp)
je     116d <parse_next_msg+0x3d>
lea    0xe9f(%rip),%rdi
lea    0xf3e(%rip),%rsi
call   1050 <fatal_error@plt>
mov    %rbp,%rdi
call   1040 <uint4@plt>
movslq %eax,%rbx
add    %rbp,%rbx
cmp    %r15,%rbx
jbe    1193 <parse_next_msg+0x63>
lea    0xe97(%rip),%rdi
lea    0xf18(%rip),%rsi
call   1050 <fatal_error@plt>
mov    $0x1,%r12d
cmp    0x40(%r14),%rbx
jae    1243 <parse_next_msg+0x113>
lea    0xefc(%rip),%rbp
lea    0xe6d(%rip),%r13
jmp    11c6 <parse_next_msg+0x96>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    0x40(%r14),%rbx
jae    1243 <parse_next_msg+0x113>
movzbl 0x4(%rbx),%eax
mov    %rbx,(%r14,%rax,8)
movzbl 0x4(%rbx),%eax
cmp    $0x6,%al
jne    1214 <parse_next_msg+0xe4>
movzbl 0x5(%rbx),%eax
test   %al,%al
je     11f3 <parse_next_msg+0xc3>
cmp    $0xfd,%al
ja     11f9 <parse_next_msg+0xc9>
lea    0xe43(%rip),%rdi
mov    %rbp,%rsi
call   1050 <fatal_error@plt>
jmp    1210 <parse_next_msg+0xe0>
mov    %rbx,0x48(%r14)
jmp    1210 <parse_next_msg+0xe0>
cmp    $0xfe,%al
jne    1210 <parse_next_msg+0xe0>
mov    0x48(%r14),%rax
mov    %rax,0x30(%r14)
test   %rax,%rax
je     1237 <parse_next_msg+0x107>
nopw   0x0(%rax,%rax,1)
movzbl 0x4(%rbx),%eax
cmp    $0x7,%al
je     1240 <parse_next_msg+0x110>
mov    %rbx,%rdi
call   1040 <uint4@plt>
cltq
add    %rax,%rbx
cmp    %r15,%rbx
jbe    11c0 <parse_next_msg+0x90>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1050 <fatal_error@plt>
jmp    11c0 <parse_next_msg+0x90>
lea    0xe21(%rip),%rdi
jmp    11e9 <parse_next_msg+0xb9>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"parse_next_msg: parsing error\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [14 x i8] c"bad grib fill\00"
@.str.3 = [51 x i8] c"parse_next_msg: predefined bitmaps are not handled\00"
@.str.4 = [72 x i8] c"parse_1st_msg: illegal grib msg, bitmap not defined code, table 6.0=254\00"
define i32 @parse_next_msg(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
store i8** %0, i8*** %3
%6 = load i8**, i8*** %3
%7 = getelementptr inbounds i8*, i8** %6, i64 0
%8 = load i8*, i8** %7
%9 = load i8**, i8*** %3
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8, i8* %11, i64 8
%13 = call i32 @uint8(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %8, i64 %14
store i8* %15, i8** %5
%16 = load i8**, i8*** %3
%17 = getelementptr inbounds i8*, i8** %16, i64 7
%18 = load i8*, i8** %17
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 4
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp ne i32 %22, 7
br i1 %23, label %24, label %26
24: ; preds = %1
%25 = call i32 @fatal_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %1
%27 = load i8*, i8** %4
%28 = call i32 @uint4(i8* %27)
%29 = load i8*, i8** %4
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = icmp ugt i8* %32, %33
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 @fatal_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %26
br label %38
38: ; preds = %118, %37
%39 = load i8*, i8** %4
%40 = load i8**, i8*** %3
%41 = getelementptr inbounds i8*, i8** %40, i64 8
%42 = load i8*, i8** %41
%43 = icmp ult i8* %39, %42
br i1 %43, label %44, label %119
44: ; preds = %38
%45 = load i8*, i8** %4
%46 = load i8**, i8*** %3
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 4
%49 = load i8, i8* %48
%50 = zext i8 %49 to i64
%51 = getelementptr inbounds i8*, i8** %46, i64 %50
store i8* %45, i8** %51
%52 = load i8*, i8** %4
%53 = getelementptr inbounds i8, i8* %52, i64 4
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = icmp eq i32 %55, 6
br i1 %56, label %57, label %100
57: ; preds = %44
%58 = load i8*, i8** %4
%59 = getelementptr inbounds i8, i8* %58, i64 5
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %57
%64 = load i8*, i8** %4
%65 = load i8**, i8*** %3
%66 = getelementptr inbounds i8*, i8** %65, i64 9
store i8* %64, i8** %66
br label %99
67: ; preds = %57
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i64 5
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = icmp sge i32 %71, 1
br i1 %72, label %73, label %81
73: ; preds = %67
%74 = load i8*, i8** %4
%75 = getelementptr inbounds i8, i8* %74, i64 5
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = icmp sle i32 %77, 253
br i1 %78, label %79, label %81
79: ; preds = %73
%80 = call i32 @fatal_error(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %98
81: ; preds = %73, %67
%82 = load i8*, i8** %4
%83 = getelementptr inbounds i8, i8* %82, i64 5
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = icmp eq i32 %85, 254
br i1 %86, label %87, label %97
87: ; preds = %81
%88 = load i8**, i8*** %3
%89 = getelementptr inbounds i8*, i8** %88, i64 9
%90 = load i8*, i8** %89
%91 = load i8**, i8*** %3
%92 = getelementptr inbounds i8*, i8** %91, i64 6
store i8* %90, i8** %92
%93 = icmp eq i8* %90, null
br i1 %93, label %94, label %96
94: ; preds = %87
%95 = call i32 @fatal_error(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %96
96: ; preds = %94, %87
br label %97
97: ; preds = %96, %81
br label %98
98: ; preds = %97, %79
br label %99
99: ; preds = %98, %63
br label %100
100: ; preds = %99, %44
%101 = load i8*, i8** %4
%102 = getelementptr inbounds i8, i8* %101, i64 4
%103 = load i8, i8* %102
%104 = zext i8 %103 to i32
%105 = icmp eq i32 %104, 7
br i1 %105, label %106, label %107
106: ; preds = %100
store i32 0, i32* %2
br label %120
107: ; preds = %100
%108 = load i8*, i8** %4
%109 = call i32 @uint4(i8* %108)
%110 = load i8*, i8** %4
%111 = sext i32 %109 to i64
%112 = getelementptr inbounds i8, i8* %110, i64 %111
store i8* %112, i8** %4
%113 = load i8*, i8** %4
%114 = load i8*, i8** %5
%115 = icmp ugt i8* %113, %114
br i1 %115, label %116, label %118
116: ; preds = %107
%117 = call i32 @fatal_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %118
118: ; preds = %116, %107
br label %38
119: ; preds = %38
store i32 1, i32* %2
br label %120
120: ; preds = %119, %106
%121 = load i32, i32* %2
ret i32 %121
}

LLVM IR (-O2):
@.str = [30 x i8] c"parse_next_msg: parsing error\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [14 x i8] c"bad grib fill\00"
@.str.3 = [51 x i8] c"parse_next_msg: predefined bitmaps are not handled\00"
@.str.4 = [72 x i8] c"parse_1st_msg: illegal grib msg, bitmap not defined code, table 6.0=254\00"
define i32 @parse_next_msg(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = getelementptr inbounds i8, i8* %2, i64 8
%4 = tail call i32 @uint8(i8* %3)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %2, i64 %5
%7 = getelementptr inbounds i8*, i8** %0, i64 7
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8, i8* %8, i64 4
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 7
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = tail call i32 @fatal_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = tail call i32 @uint4(i8* %8)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %8, i64 %16
%18 = icmp ugt i8* %17, %6
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @fatal_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = getelementptr inbounds i8*, i8** %0, i64 8
%23 = load i8*, i8** %22
%24 = icmp ult i8* %17, %23
br i1 %24, label %25, label %67
25: ; preds = %21
%26 = getelementptr inbounds i8*, i8** %0, i64 9
%27 = getelementptr inbounds i8*, i8** %0, i64 6
br label %28
28: ; preds = %25, %64
%29 = phi i8* [ %17, %25 ], [ %60, %64 ]
%30 = getelementptr inbounds i8, i8* %29, i64 4
%31 = load i8, i8* %30
%32 = zext i8 %31 to i64
%33 = getelementptr inbounds i8*, i8** %0, i64 %32
store i8* %29, i8** %33
%34 = load i8, i8* %30
%35 = icmp eq i8 %34, 6
br i1 %35, label %36, label %54
36: ; preds = %28
%37 = getelementptr inbounds i8, i8* %29, i64 5
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
store i8* %29, i8** %26
br label %52
41: ; preds = %36
%42 = icmp ult i8 %38, -2
br i1 %42, label %43, label %45
43: ; preds = %41
%44 = tail call i32 @fatal_error(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %52
45: ; preds = %41
%46 = icmp eq i8 %38, -2
br i1 %46, label %47, label %52
47: ; preds = %45
%48 = load i8*, i8** %26
store i8* %48, i8** %27
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = tail call i32 @fatal_error(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %43, %47, %50, %45, %40
%53 = load i8, i8* %30
br label %54
54: ; preds = %52, %28
%55 = phi i8 [ %53, %52 ], [ %34, %28 ]
%56 = icmp eq i8 %55, 7
br i1 %56, label %67, label %57
57: ; preds = %54
%58 = tail call i32 @uint4(i8* %29)
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %29, i64 %59
%61 = icmp ugt i8* %60, %6
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = tail call i32 @fatal_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %64
64: ; preds = %62, %57
%65 = load i8*, i8** %22
%66 = icmp ult i8* %60, %65
br i1 %66, label %28, label %67
67: ; preds = %54, %64, %21
%68 = phi i32 [ 1, %21 ], [ 1, %64 ], [ 0, %54 ]
ret i32 %68
}