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

/* Variables and functions */
int FindStartCode(unsigned char *, int);
int /*<<< orphan*/ SEEK_CUR;
scalar_t__ feof(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int getNextNal(FILE *inpf, unsigned char *Buf) {
  int pos = 0;
  int StartCodeFound = 0;
  int info2 = 0;
  int info3 = 0;
  while (!feof(inpf) && (Buf[pos++] = fgetc(inpf)) == 0)
    ;
  while (!StartCodeFound) {
    if (feof(inpf)) {
      return pos - 1;
    }
    Buf[pos++] = fgetc(inpf);
    info3 = FindStartCode(&Buf[pos - 4], 3);
    if (info3 != 1)
      info2 = FindStartCode(&Buf[pos - 3], 2);
    StartCodeFound = (info2 == 1 || info3 == 1);
  }
  fseek(inpf, -4, SEEK_CUR);
  return pos - 4;
}


x86 assembly (clang, -O0):
<getNextNal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
jne    11b1 <getNextNal+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %edx,%rdx
mov    %al,(%rcx,%rdx,1)
movzbl %al,%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11c1 <getNextNal+0x81>
jmp    11c6 <getNextNal+0x86>
jmp    116c <getNextNal+0x2c>
jmp    11cb <getNextNal+0x8b>
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e1 <getNextNal+0xa1>
jmp    128d <getNextNal+0x14d>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1202 <getNextNal+0xc2>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12ad <getNextNal+0x16d>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
sub    $0x4,%eax
cltq
add    %rax,%rdi
mov    $0x3,%esi
call   1050 <FindStartCode@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
je     1264 <getNextNal+0x124>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
cltq
add    %rax,%rdi
mov    $0x2,%esi
call   1050 <FindStartCode@plt>
mov    %eax,-0x24(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x24(%rbp)
mov    %al,-0x2a(%rbp)
je     127d <getNextNal+0x13d>
cmpl   $0x1,-0x28(%rbp)
sete   %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
jmp    11cb <getNextNal+0x8b>
mov    -0x10(%rbp),%rdi
mov    0x2d50(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   1060 <fseek@plt>
mov    -0x1c(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNextNal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %ebp,%ebp
nop
mov    %r14,%rdi
call   1040 <feof@plt>
test   %rax,%rax
jne    1170 <getNextNal+0x30>
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
test   %al,%al
je     1150 <getNextNal+0x10>
movslq %ebp,%rcx
lea    -0x3(%rcx),%eax
add    %rcx,%rbx
add    $0xfffffffffffffffd,%rbx
nopl   (%rax)
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <feof@plt>
test   %rax,%rax
jne    11e6 <getNextNal+0xa6>
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %al,0x3(%rbx)
mov    %rbx,%rdi
mov    $0x3,%esi
call   1050 <FindStartCode@plt>
cmp    $0x1,%eax
je     11ce <getNextNal+0x8e>
mov    %eax,%ebp
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <FindStartCode@plt>
cmp    $0x1,%eax
je     11ce <getNextNal+0x8e>
lea    0x1(%r15),%eax
cmp    $0x1,%ebp
jne    1180 <getNextNal+0x40>
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0xfffffffc,%esi
call   1060 <fseek@plt>
jmp    11ea <getNextNal+0xaa>
add    $0x2,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define i32 @getNextNal(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %26, %2
%11 = load i32*, i32** %4
%12 = call i64 @feof(i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = call zeroext i8 @fgetc(i32* %15)
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 %16, i8* %21
%22 = zext i8 %16 to i32
%23 = icmp eq i32 %22, 0
br label %24
24: ; preds = %14, %10
%25 = phi i1 [ false, %10 ], [ %23, %14 ]
br i1 %25, label %26, label %27
26: ; preds = %24
br label %10
27: ; preds = %24
br label %28
28: ; preds = %68, %27
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
br i1 %31, label %32, label %71
32: ; preds = %28
%33 = load i32*, i32** %4
%34 = call i64 @feof(i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32, i32* %6
%38 = sub nsw i32 %37, 1
store i32 %38, i32* %3
br label %77
39: ; preds = %32
%40 = load i32*, i32** %4
%41 = call zeroext i8 @fgetc(i32* %40)
%42 = load i8*, i8** %5
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 %41, i8* %46
%47 = load i8*, i8** %5
%48 = load i32, i32* %6
%49 = sub nsw i32 %48, 4
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = call i32 @FindStartCode(i8* %51, i32 3)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = icmp ne i32 %53, 1
br i1 %54, label %55, label %62
55: ; preds = %39
%56 = load i8*, i8** %5
%57 = load i32, i32* %6
%58 = sub nsw i32 %57, 3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
%61 = call i32 @FindStartCode(i8* %60, i32 2)
store i32 %61, i32* %8
br label %62
62: ; preds = %55, %39
%63 = load i32, i32* %8
%64 = icmp eq i32 %63, 1
br i1 %64, label %68, label %65
65: ; preds = %62
%66 = load i32, i32* %9
%67 = icmp eq i32 %66, 1
br label %68
68: ; preds = %65, %62
%69 = phi i1 [ true, %62 ], [ %67, %65 ]
%70 = zext i1 %69 to i32
store i32 %70, i32* %7
br label %28
71: ; preds = %28
%72 = load i32*, i32** %4
%73 = load i32, i32* @SEEK_CUR
%74 = call i32 @fseek(i32* %72, i32 -4, i32 %73)
%75 = load i32, i32* %6
%76 = sub nsw i32 %75, 4
store i32 %76, i32* %3
br label %77
77: ; preds = %71, %36
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define i32 @getNextNal(i32* nocapture %0, i8* %1) {
br label %3
3: ; preds = %7, %2
%4 = phi i64 [ %9, %7 ], [ 0, %2 ]
%5 = tail call i64 @feof(i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = tail call zeroext i8 @fgetc(i32* %0)
%9 = add nuw i64 %4, 1
%10 = getelementptr inbounds i8, i8* %1, i64 %4
store i8 %8, i8* %10
%11 = icmp eq i8 %8, 0
br i1 %11, label %3, label %12
12: ; preds = %3, %7
%13 = phi i64 [ %4, %3 ], [ %9, %7 ]
%14 = shl i64 %13, 32
%15 = ashr exact i64 %14, 32
br label %16
16: ; preds = %12, %30
%17 = phi i64 [ %15, %12 ], [ %31, %30 ]
%18 = tail call i64 @feof(i32* %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = trunc i64 %17 to i32
%22 = add nsw i32 %21, -1
br label %42
23: ; preds = %16
%24 = tail call zeroext i8 @fgetc(i32* %0)
%25 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 %24, i8* %25
%26 = add nsw i64 %17, -3
%27 = getelementptr inbounds i8, i8* %1, i64 %26
%28 = tail call i32 @FindStartCode(i8* %27, i32 3)
%29 = icmp eq i32 %28, 1
br i1 %29, label %37, label %30
30: ; preds = %23
%31 = add i64 %17, 1
%32 = add nsw i64 %17, -2
%33 = getelementptr inbounds i8, i8* %1, i64 %32
%34 = tail call i32 @FindStartCode(i8* %33, i32 2)
%35 = icmp eq i32 %34, 1
%36 = select i1 %35, i1 true, i1 %29
br i1 %36, label %37, label %16
37: ; preds = %23, %30
%38 = trunc i64 %17 to i32
%39 = load i32, i32* @SEEK_CUR
%40 = tail call i32 @fseek(i32* %0, i32 -4, i32 %39)
%41 = add nsw i32 %38, -3
br label %42
42: ; preds = %37, %20
%43 = phi i32 [ %22, %20 ], [ %41, %37 ]
ret i32 %43
}