#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*/ cdoAbort(char *);
int /*<<< orphan*/ cdoPrint(char *, ...);
int gridInqSize(int);
int /*<<< orphan*/ gridInqType(int);
int /*<<< orphan*/ gridNamePtr(int /*<<< orphan*/);
int vlistGrid(int, int);
int vlistNgrids(int);
int vlist_check_gridsize(int vlistID) {
  int lerror = 0;
  int ngrids = vlistNgrids(vlistID);
  int gridID = vlistGrid(vlistID, 0);
  int ngp = gridInqSize(gridID);
  for (int index = 0; index < ngrids; ++index) {
    gridID = vlistGrid(vlistID, index);
    if (ngp != gridInqSize(gridID)) {
      lerror = 1;
      break;
    }
  }
  if (lerror) {
    cdoPrint(
        "This operator requires all variables on the same horizontal grid.");
    cdoPrint("Horizontal grids found:");
    for (int index = 0; index < ngrids; ++index) {
      gridID = vlistGrid(vlistID, index);
      cdoPrint("  grid=%d  type=%s  points=%d", index + 1,
               gridNamePtr(gridInqType(gridID)), gridInqSize(gridID));
    }
    cdoAbort(
        "The input stream contains variables on different horizontal grids!");
  }
  return ngp;
}


x86 assembly (clang, -O0):
<vlist_check_gridsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <vlistNgrids@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <vlistGrid@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1090 <gridInqSize@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1200 <vlist_check_gridsize+0x90>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <vlistGrid@plt>
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
call   1090 <gridInqSize@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
je     11ed <vlist_check_gridsize+0x7d>
movl   $0x1,-0x8(%rbp)
jmp    1200 <vlist_check_gridsize+0x90>
jmp    11f2 <vlist_check_gridsize+0x82>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ac <vlist_check_gridsize+0x3c>
cmpl   $0x0,-0x8(%rbp)
je     129a <vlist_check_gridsize+0x12a>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <cdoPrint@plt>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <cdoPrint@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    128e <vlist_check_gridsize+0x11e>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <vlistGrid@plt>
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
call   1080 <gridInqType@plt>
mov    %eax,%edi
call   1070 <gridNamePtr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%edi
call   1090 <gridInqSize@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1050 <cdoPrint@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122d <vlist_check_gridsize+0xbd>
lea    0xde3(%rip),%rdi
call   1060 <cdoAbort@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vlist_check_gridsize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
call   1040 <vlistNgrids@plt>
mov    %eax,%r12d
xor    %ebp,%ebp
mov    %r13d,%edi
xor    %esi,%esi
call   1030 <vlistGrid@plt>
mov    %eax,%edi
call   1090 <gridInqSize@plt>
mov    %eax,%r14d
test   %r12d,%r12d
jle    123d <vlist_check_gridsize+0xcd>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%edi
mov    %ebp,%esi
call   1030 <vlistGrid@plt>
mov    %eax,%edi
call   1090 <gridInqSize@plt>
cmp    %eax,%r14d
jne    11d0 <vlist_check_gridsize+0x60>
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    11b0 <vlist_check_gridsize+0x40>
jmp    123d <vlist_check_gridsize+0xcd>
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1050 <cdoPrint@plt>
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1050 <cdoPrint@plt>
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r13d,%edi
mov    %ebp,%esi
call   1030 <vlistGrid@plt>
mov    %eax,%ebx
add    $0x1,%ebp
mov    %eax,%edi
call   1080 <gridInqType@plt>
mov    %eax,%edi
call   1070 <gridNamePtr@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1090 <gridInqSize@plt>
lea    0xe3c(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <cdoPrint@plt>
cmp    %ebp,%r12d
jne    11f0 <vlist_check_gridsize+0x80>
lea    0xe40(%rip),%rdi
call   1060 <cdoAbort@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"This operator requires all variables on the same horizontal grid.\00"
@.str.1 = [24 x i8] c"Horizontal grids found:\00"
@.str.2 = [30 x i8] c" grid=%d type=%s points=%d\00"
@.str.3 = [67 x i8] c"The input stream contains variables on different horizontal grids!\00"
define i32 @vlist_check_gridsize(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%9 = load i32, i32* %2
%10 = call i32 @vlistNgrids(i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %2
%12 = call i32 @vlistGrid(i32 %11, i32 0)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = call i32 @gridInqSize(i32 %13)
store i32 %14, i32* %6
store i32 0, i32* %7
br label %15
15: ; preds = %29, %1
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i32, i32* %2
%21 = load i32, i32* %7
%22 = call i32 @vlistGrid(i32 %20, i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %6
%24 = load i32, i32* %5
%25 = call i32 @gridInqSize(i32 %24)
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %28
27: ; preds = %19
store i32 1, i32* %3
br label %32
28: ; preds = %19
br label %29
29: ; preds = %28
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %15
32: ; preds = %27, %15
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %59
35: ; preds = %32
%36 = call i32 (i8*, ...) @cdoPrint(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%37 = call i32 (i8*, ...) @cdoPrint(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %38
38: ; preds = %54, %35
%39 = load i32, i32* %8
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %57
42: ; preds = %38
%43 = load i32, i32* %2
%44 = load i32, i32* %8
%45 = call i32 @vlistGrid(i32 %43, i32 %44)
store i32 %45, i32* %5
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
%48 = load i32, i32* %5
%49 = call i32 @gridInqType(i32 %48)
%50 = call i32 @gridNamePtr(i32 %49)
%51 = load i32, i32* %5
%52 = call i32 @gridInqSize(i32 %51)
%53 = call i32 (i8*, ...) @cdoPrint(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 %50, i32 %52)
br label %54
54: ; preds = %42
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %38
57: ; preds = %38
%58 = call i32 @cdoAbort(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %57, %32
%60 = load i32, i32* %6
ret i32 %60
}

LLVM IR (-O2):
@.str = [66 x i8] c"This operator requires all variables on the same horizontal grid.\00"
@.str.1 = [24 x i8] c"Horizontal grids found:\00"
@.str.2 = [30 x i8] c" grid=%d type=%s points=%d\00"
@.str.3 = [67 x i8] c"The input stream contains variables on different horizontal grids!\00"
define i32 @vlist_check_gridsize(i32 %0) {
%2 = tail call i32 @vlistNgrids(i32 %0)
%3 = tail call i32 @vlistGrid(i32 %0, i32 0)
%4 = tail call i32 @gridInqSize(i32 %3)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %8, label %28
6: ; preds = %8
%7 = icmp eq i32 %13, %2
br i1 %7, label %28, label %8
8: ; preds = %1, %6
%9 = phi i32 [ %13, %6 ], [ 0, %1 ]
%10 = tail call i32 @vlistGrid(i32 %0, i32 %9)
%11 = tail call i32 @gridInqSize(i32 %10)
%12 = icmp eq i32 %4, %11
%13 = add nuw nsw i32 %9, 1
br i1 %12, label %6, label %14
14: ; preds = %8
%15 = tail call i32 (i8*, ...) @cdoPrint(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @cdoPrint(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %19
17: ; preds = %19
%18 = tail call i32 @cdoAbort(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0))
br label %28
19: ; preds = %14, %19
%20 = phi i32 [ %22, %19 ], [ 0, %14 ]
%21 = tail call i32 @vlistGrid(i32 %0, i32 %20)
%22 = add nuw nsw i32 %20, 1
%23 = tail call i32 @gridInqType(i32 %21)
%24 = tail call i32 @gridNamePtr(i32 %23)
%25 = tail call i32 @gridInqSize(i32 %21)
%26 = tail call i32 (i8*, ...) @cdoPrint(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %24, i32 %25)
%27 = icmp eq i32 %22, %2
br i1 %27, label %17, label %19
28: ; preds = %6, %1, %17
ret i32 %4
}