#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 RIFF_NextChunk(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ RIFF_ReadChunkInfo(int /*<<< orphan*/ *, int, int *, int *,
                                      int *);
int RIFF_FindSubChunk(FILE *fd, int ofs, int id, int lid) {
  int cc1, cc2, sz;
  int end, cur;
  RIFF_ReadChunkInfo(fd, ofs, &cc1, &sz, &cc2);
  end = ofs + sz + 8;
  cur = ofs + 12;
  while (cur < end) {
    RIFF_ReadChunkInfo(fd, cur, &cc1, &sz, &cc2);
    if (cc1 == id)
      if (!lid || (cc2 == lid))
        return (cur);
    cur = RIFF_NextChunk(fd, cur);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<RIFF_FindSubChunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1040 <RIFF_ReadChunkInfo@plt>
mov    -0x14(%rbp),%eax
add    -0x28(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11cc <RIFF_FindSubChunk+0xac>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1040 <RIFF_ReadChunkInfo@plt>
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11b8 <RIFF_FindSubChunk+0x98>
cmpl   $0x0,-0x1c(%rbp)
je     11a8 <RIFF_FindSubChunk+0x88>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11b3 <RIFF_FindSubChunk+0x93>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d3 <RIFF_FindSubChunk+0xb3>
jmp    11b8 <RIFF_FindSubChunk+0x98>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1030 <RIFF_NextChunk@plt>
mov    %eax,-0x30(%rbp)
jmp    1162 <RIFF_FindSubChunk+0x42>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RIFF_FindSubChunk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%rbp
lea    0x14(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r8
call   1040 <RIFF_ReadChunkInfo@plt>
mov    0xc(%rsp),%eax
lea    (%rbx,%rax,1),%r12d
add    $0x8,%r12d
add    $0xc,%ebx
mov    $0xffffffff,%eax
cmp    %r12d,%ebx
jge    11b4 <RIFF_FindSubChunk+0x94>
lea    0x10(%rsp),%r13
jmp    1181 <RIFF_FindSubChunk+0x61>
nopl   (%rax)
mov    %rbp,%rdi
mov    %ebx,%esi
call   1030 <RIFF_NextChunk@plt>
mov    %eax,%ebx
cmp    %r12d,%eax
jge    11af <RIFF_FindSubChunk+0x8f>
mov    %rbp,%rdi
mov    %ebx,%esi
lea    0x14(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r13,%r8
call   1040 <RIFF_ReadChunkInfo@plt>
cmp    %r15d,0x14(%rsp)
jne    1170 <RIFF_FindSubChunk+0x50>
test   %r14d,%r14d
je     11ab <RIFF_FindSubChunk+0x8b>
cmp    %r14d,0x10(%rsp)
jne    1170 <RIFF_FindSubChunk+0x50>
mov    %ebx,%eax
jmp    11b4 <RIFF_FindSubChunk+0x94>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @RIFF_FindSubChunk(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%15 = load i32*, i32** %6
%16 = load i32, i32* %7
%17 = call i32 @RIFF_ReadChunkInfo(i32* %15, i32 %16, i32* %10, i32* %12, i32* %11)
%18 = load i32, i32* %7
%19 = load i32, i32* %12
%20 = add nsw i32 %18, %19
%21 = add nsw i32 %20, 8
store i32 %21, i32* %13
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 12
store i32 %23, i32* %14
br label %24
24: ; preds = %45, %4
%25 = load i32, i32* %14
%26 = load i32, i32* %13
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %49
28: ; preds = %24
%29 = load i32*, i32** %6
%30 = load i32, i32* %14
%31 = call i32 @RIFF_ReadChunkInfo(i32* %29, i32 %30, i32* %10, i32* %12, i32* %11)
%32 = load i32, i32* %10
%33 = load i32, i32* %8
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %45
35: ; preds = %28
%36 = load i32, i32* %9
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i32, i32* %11
%40 = load i32, i32* %9
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38, %35
%43 = load i32, i32* %14
store i32 %43, i32* %5
br label %50
44: ; preds = %38
br label %45
45: ; preds = %44, %28
%46 = load i32*, i32** %6
%47 = load i32, i32* %14
%48 = call i32 @RIFF_NextChunk(i32* %46, i32 %47)
store i32 %48, i32* %14
br label %24
49: ; preds = %24
store i32 -1, i32* %5
br label %50
50: ; preds = %49, %42
%51 = load i32, i32* %5
ret i32 %51
}

LLVM IR (-O2):
define i32 @RIFF_FindSubChunk(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = call i32 @RIFF_ReadChunkInfo(i32* %0, i32 %1, i32* %5, i32* %7, i32* %6)
%12 = load i32, i32* %7
%13 = add i32 %1, 8
%14 = add i32 %13, %12
%15 = add nsw i32 %1, 12
%16 = icmp slt i32 %15, %14
br i1 %16, label %17, label %31
17: ; preds = %4
%18 = icmp eq i32 %3, 0
br label %19
19: ; preds = %17, %28
%20 = phi i32 [ %15, %17 ], [ %29, %28 ]
%21 = call i32 @RIFF_ReadChunkInfo(i32* %0, i32 %20, i32* %5, i32* %7, i32* %6)
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, %2
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, %3
%27 = select i1 %18, i1 true, i1 %26
br i1 %27, label %31, label %28
28: ; preds = %24, %19
%29 = call i32 @RIFF_NextChunk(i32* %0, i32 %20)
%30 = icmp slt i32 %29, %14
br i1 %30, label %19, label %31
31: ; preds = %24, %28, %4
%32 = phi i32 [ -1, %4 ], [ -1, %28 ], [ %20, %24 ]
ret i32 %32
}