#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 vlistNzaxis(int);
int vlistZaxis(int, int);
int zaxisCreate(int /*<<< orphan*/, int);
int zaxisInqSize(int);
scalar_t__ zaxisInqType(int);
int getSurfaceID(int vlistID) {
  int surfID = -1;
  int zaxisID;
  int nzaxis = vlistNzaxis(vlistID);
  for (int index = 0; index < nzaxis; ++index) {
    zaxisID = vlistZaxis(vlistID, index);
    if ((zaxisInqType(zaxisID) == 0 && zaxisInqSize(zaxisID) == 1)) {
      surfID = vlistZaxis(vlistID, index);
      break;
    }
  }
  if (surfID == -1)
    surfID = zaxisCreate(0, 1);
  return surfID;
}


x86 assembly (clang, -O0):
<getSurfaceID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <vlistNzaxis@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d7 <getSurfaceID+0x87>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <vlistZaxis@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <zaxisInqType@plt>
cmp    $0x0,%rax
jne    11c4 <getSurfaceID+0x74>
mov    -0xc(%rbp),%edi
call   1030 <zaxisInqSize@plt>
cmp    $0x1,%eax
jne    11c4 <getSurfaceID+0x74>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <vlistZaxis@plt>
mov    %eax,-0x8(%rbp)
jmp    11d7 <getSurfaceID+0x87>
jmp    11c9 <getSurfaceID+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1174 <getSurfaceID+0x24>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11f0 <getSurfaceID+0xa0>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <zaxisCreate@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSurfaceID>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
call   1070 <vlistNzaxis@plt>
test   %eax,%eax
jle    11b6 <getSurfaceID+0x66>
mov    %eax,%r15d
xor    %ebx,%ebx
jmp    1178 <getSurfaceID+0x28>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%r15d
je     11b6 <getSurfaceID+0x66>
mov    %r14d,%edi
mov    %ebx,%esi
call   1040 <vlistZaxis@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <zaxisInqType@plt>
test   %rax,%rax
jne    1170 <getSurfaceID+0x20>
mov    %ebp,%edi
call   1030 <zaxisInqSize@plt>
cmp    $0x1,%eax
jne    1170 <getSurfaceID+0x20>
mov    %r14d,%edi
mov    %ebx,%esi
call   1040 <vlistZaxis@plt>
cmp    $0xffffffff,%eax
je     11b6 <getSurfaceID+0x66>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
mov    $0x1,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <zaxisCreate@plt>

LLVM IR (-O0):
define i32 @getSurfaceID(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 -1, i32* %3
%7 = load i32, i32* %2
%8 = call i32 @vlistNzaxis(i32 %7)
store i32 %8, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %29, %1
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %32
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i32, i32* %6
%16 = call i32 @vlistZaxis(i32 %14, i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = call i64 @zaxisInqType(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %13
%21 = load i32, i32* %4
%22 = call i32 @zaxisInqSize(i32 %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* %2
%26 = load i32, i32* %6
%27 = call i32 @vlistZaxis(i32 %25, i32 %26)
store i32 %27, i32* %3
br label %32
28: ; preds = %20, %13
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %9
32: ; preds = %24, %9
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @zaxisCreate(i32 0, i32 1)
store i32 %36, i32* %3
br label %37
37: ; preds = %35, %32
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @getSurfaceID(i32 %0) {
%2 = tail call i32 @vlistNzaxis(i32 %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %18
4: ; preds = %1, %12
%5 = phi i32 [ %13, %12 ], [ 0, %1 ]
%6 = tail call i32 @vlistZaxis(i32 %0, i32 %5)
%7 = tail call i64 @zaxisInqType(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 @zaxisInqSize(i32 %6)
%11 = icmp eq i32 %10, 1
br i1 %11, label %15, label %12
12: ; preds = %4, %9
%13 = add nuw nsw i32 %5, 1
%14 = icmp eq i32 %13, %2
br i1 %14, label %18, label %4
15: ; preds = %9
%16 = tail call i32 @vlistZaxis(i32 %0, i32 %5)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %12, %1, %15
%19 = tail call i32 @zaxisCreate(i32 0, i32 1)
br label %20
20: ; preds = %18, %15
%21 = phi i32 [ %19, %18 ], [ %16, %15 ]
ret i32 %21
}