#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*/ fatal_error_i(char *, int);
int /*<<< orphan*/ uint4(unsigned char *);
int parse_1st_msg(unsigned char **sec) {
  unsigned char *p;
  if (sec[0] == NULL)
    fatal_error("parse_1st_msg .. sec[0] == NULL", "");
  sec[2] = sec[6] = NULL;
  sec[9] = NULL;
  p = sec[0] + 16;
  while (sec[8] - p > 0) {
    if (p[4] > 8)
      fatal_error_i("parse_1st_msg illegal section %d", (int)p[4]);
    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_1st_msg: predefined bitmaps are not handled", "");
      } else if (p[5] == 254) {
        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);
  }
  fatal_error("parse_1st_msg illegally format grib", "");
  return 1;
}


x86 assembly (clang, -O0):
<parse_1st_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    115d <parse_1st_msg+0x2d>
lea    0xeaf(%rip),%rdi
lea    0xf62(%rip),%rsi
call   1050 <fatal_error@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,0x30(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x48(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x40(%rax),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x0,%rax
jle    12c1 <parse_1st_msg+0x191>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0x8,%eax
jle    11ce <parse_1st_msg+0x9e>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%esi
lea    0xe57(%rip),%rdi
call   1030 <fatal_error_i@plt>
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    1286 <parse_1st_msg+0x156>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0x0,%eax
jne    1215 <parse_1st_msg+0xe5>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x48(%rax)
jmp    1281 <parse_1st_msg+0x151>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0x1,%eax
jl     1251 <parse_1st_msg+0x121>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0xfd,%eax
jg     1251 <parse_1st_msg+0x121>
lea    0xe01(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1050 <fatal_error@plt>
jmp    127c <parse_1st_msg+0x14c>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0xfe,%eax
jne    1277 <parse_1st_msg+0x147>
lea    0xe08(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1050 <fatal_error@plt>
jmp    127c <parse_1st_msg+0x14c>
jmp    1281 <parse_1st_msg+0x151>
jmp    1286 <parse_1st_msg+0x156>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0x7,%eax
jne    12a3 <parse_1st_msg+0x173>
movl   $0x0,-0x4(%rbp)
jmp    12db <parse_1st_msg+0x1ab>
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)
jmp    1190 <parse_1st_msg+0x60>
lea    0xdf3(%rip),%rdi
lea    0xdeb(%rip),%rsi
call   1050 <fatal_error@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_1st_msg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rbx
test   %rbx,%rbx
jne    115c <parse_1st_msg+0x2c>
lea    0xeb3(%rip),%rdi
lea    0xf66(%rip),%rsi
call   1050 <fatal_error@plt>
mov    (%r14),%rbx
movq   $0x0,0x30(%r14)
movq   $0x0,0x10(%r14)
movq   $0x0,0x48(%r14)
add    $0x10,%rbx
mov    0x40(%r14),%rax
sub    %rbx,%rax
test   %rax,%rax
jle    121c <parse_1st_msg+0xec>
lea    0xe91(%rip),%r15
lea    0xeab(%rip),%r12
lea    0xf1d(%rip),%r13
lea    0xecf(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x4(%rbx),%esi
cmp    $0x9,%esi
jb     11c5 <parse_1st_msg+0x95>
mov    %r15,%rdi
call   1030 <fatal_error_i@plt>
movzbl 0x4(%rbx),%esi
movzbl %sil,%eax
mov    %rbx,(%r14,%rax,8)
movzbl 0x4(%rbx),%eax
cmp    $0x6,%al
jne    11ff <parse_1st_msg+0xcf>
movzbl 0x5(%rbx),%eax
test   %al,%al
je     11e6 <parse_1st_msg+0xb6>
cmp    $0xfd,%al
ja     11ec <parse_1st_msg+0xbc>
mov    %r12,%rdi
jmp    11f3 <parse_1st_msg+0xc3>
mov    %rbx,0x48(%r14)
jmp    11fb <parse_1st_msg+0xcb>
cmp    $0xfe,%al
jne    11fb <parse_1st_msg+0xcb>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <fatal_error@plt>
movzbl 0x4(%rbx),%eax
cmp    $0x7,%al
je     1236 <parse_1st_msg+0x106>
mov    %rbx,%rdi
call   1040 <uint4@plt>
cltq
add    %rax,%rbx
mov    0x40(%r14),%rax
sub    %rbx,%rax
test   %rax,%rax
jg     11b0 <parse_1st_msg+0x80>
lea    0xe98(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1050 <fatal_error@plt>
mov    $0x1,%eax
jmp    1238 <parse_1st_msg+0x108>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"parse_1st_msg .. sec[0] == NULL\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [33 x i8] c"parse_1st_msg illegal section %d\00"
@.str.3 = [50 x i8] c"parse_1st_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"
@.str.5 = [36 x i8] c"parse_1st_msg illegally format grib\00"
define i32 @parse_1st_msg(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
store i8** %0, i8*** %3
%5 = load i8**, i8*** %3
%6 = getelementptr inbounds i8*, i8** %5, i64 0
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @fatal_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i8**, i8*** %3
%13 = getelementptr inbounds i8*, i8** %12, i64 6
store i8* null, i8** %13
%14 = load i8**, i8*** %3
%15 = getelementptr inbounds i8*, i8** %14, i64 2
store i8* null, i8** %15
%16 = load i8**, i8*** %3
%17 = getelementptr inbounds i8*, i8** %16, i64 9
store i8* null, i8** %17
%18 = load i8**, i8*** %3
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 16
store i8* %21, i8** %4
br label %22
22: ; preds = %98, %11
%23 = load i8**, i8*** %3
%24 = getelementptr inbounds i8*, i8** %23, i64 8
%25 = load i8*, i8** %24
%26 = load i8*, i8** %4
%27 = ptrtoint i8* %25 to i64
%28 = ptrtoint i8* %26 to i64
%29 = sub i64 %27, %28
%30 = icmp sgt i64 %29, 0
br i1 %30, label %31, label %104
31: ; preds = %22
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 4
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = icmp sgt i32 %35, 8
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 4
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = call i32 @fatal_error_i(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %37, %31
%44 = load i8*, i8** %4
%45 = load i8**, i8*** %3
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 4
%48 = load i8, i8* %47
%49 = zext i8 %48 to i64
%50 = getelementptr inbounds i8*, i8** %45, i64 %49
store i8* %44, i8** %50
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i64 4
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp eq i32 %54, 6
br i1 %55, label %56, label %91
56: ; preds = %43
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 5
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %56
%63 = load i8*, i8** %4
%64 = load i8**, i8*** %3
%65 = getelementptr inbounds i8*, i8** %64, i64 9
store i8* %63, i8** %65
br label %90
66: ; preds = %56
%67 = load i8*, i8** %4
%68 = getelementptr inbounds i8, i8* %67, i64 5
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = icmp sge i32 %70, 1
br i1 %71, label %72, label %80
72: ; preds = %66
%73 = load i8*, i8** %4
%74 = getelementptr inbounds i8, i8* %73, i64 5
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = icmp sle i32 %76, 253
br i1 %77, label %78, label %80
78: ; preds = %72
%79 = call i32 @fatal_error(i8* getelementptr inbounds ([50 x i8], [50 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 %89
80: ; preds = %72, %66
%81 = load i8*, i8** %4
%82 = getelementptr inbounds i8, i8* %81, i64 5
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = icmp eq i32 %84, 254
br i1 %85, label %86, label %88
86: ; preds = %80
%87 = 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 %88
88: ; preds = %86, %80
br label %89
89: ; preds = %88, %78
br label %90
90: ; preds = %89, %62
br label %91
91: ; preds = %90, %43
%92 = load i8*, i8** %4
%93 = getelementptr inbounds i8, i8* %92, i64 4
%94 = load i8, i8* %93
%95 = zext i8 %94 to i32
%96 = icmp eq i32 %95, 7
br i1 %96, label %97, label %98
97: ; preds = %91
store i32 0, i32* %2
br label %106
98: ; preds = %91
%99 = load i8*, i8** %4
%100 = call i32 @uint4(i8* %99)
%101 = load i8*, i8** %4
%102 = sext i32 %100 to i64
%103 = getelementptr inbounds i8, i8* %101, i64 %102
store i8* %103, i8** %4
br label %22
104: ; preds = %22
%105 = call i32 @fatal_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %106
106: ; preds = %104, %97
%107 = load i32, i32* %2
ret i32 %107
}

LLVM IR (-O2):
@.str = [32 x i8] c"parse_1st_msg .. sec[0] == NULL\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [33 x i8] c"parse_1st_msg illegal section %d\00"
@.str.3 = [50 x i8] c"parse_1st_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"
@.str.5 = [36 x i8] c"parse_1st_msg illegally format grib\00"
define i32 @parse_1st_msg(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @fatal_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%6 = load i8*, i8** %0
br label %7
7: ; preds = %4, %1
%8 = phi i8* [ %6, %4 ], [ %2, %1 ]
%9 = getelementptr inbounds i8*, i8** %0, i64 6
store i8* null, i8** %9
%10 = getelementptr inbounds i8*, i8** %0, i64 2
store i8* null, i8** %10
%11 = getelementptr inbounds i8*, i8** %0, i64 9
store i8* null, i8** %11
%12 = getelementptr inbounds i8, i8* %8, i64 16
%13 = getelementptr inbounds i8*, i8** %0, i64 8
%14 = load i8*, i8** %13
%15 = ptrtoint i8* %14 to i64
%16 = ptrtoint i8* %12 to i64
%17 = sub i64 %15, %16
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %61
19: ; preds = %7, %52
%20 = phi i8* [ %55, %52 ], [ %12, %7 ]
%21 = getelementptr inbounds i8, i8* %20, i64 4
%22 = load i8, i8* %21
%23 = icmp ugt i8 %22, 8
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = zext i8 %22 to i32
%26 = tail call i32 @fatal_error_i(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i8, i8* %21
br label %28
28: ; preds = %24, %19
%29 = phi i8 [ %27, %24 ], [ %22, %19 ]
%30 = zext i8 %29 to i64
%31 = getelementptr inbounds i8*, i8** %0, i64 %30
store i8* %20, i8** %31
%32 = load i8, i8* %21
%33 = icmp eq i8 %32, 6
br i1 %33, label %34, label %49
34: ; preds = %28
%35 = getelementptr inbounds i8, i8* %20, i64 5
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i8* %20, i8** %11
br label %47
39: ; preds = %34
%40 = icmp ult i8 %36, -2
br i1 %40, label %41, label %43
41: ; preds = %39
%42 = tail call i32 @fatal_error(i8* getelementptr inbounds ([50 x i8], [50 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 %47
43: ; preds = %39
%44 = icmp eq i8 %36, -2
br i1 %44, label %45, label %47
45: ; preds = %43
%46 = 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 %47
47: ; preds = %41, %45, %43, %38
%48 = load i8, i8* %21
br label %49
49: ; preds = %47, %28
%50 = phi i8 [ %48, %47 ], [ %32, %28 ]
%51 = icmp eq i8 %50, 7
br i1 %51, label %63, label %52
52: ; preds = %49
%53 = tail call i32 @uint4(i8* %20)
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %20, i64 %54
%56 = load i8*, i8** %13
%57 = ptrtoint i8* %56 to i64
%58 = ptrtoint i8* %55 to i64
%59 = sub i64 %57, %58
%60 = icmp sgt i64 %59, 0
br i1 %60, label %19, label %61
61: ; preds = %52, %7
%62 = tail call i32 @fatal_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %63
63: ; preds = %49, %61
%64 = phi i32 [ 1, %61 ], [ 0, %49 ]
ret i32 %64
}