#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 scalar_t__ u_short;
typedef int /*<<< orphan*/ u_char;

/* Variables and functions */
scalar_t__ SmbGetRecord(int /*<<< orphan*/ **);
int SmbGetRecordByNumber(u_short wNumber, void **ppRecord) {
  u_char *pSaveState = NULL;
  u_short wIndex = 0;
  while (SmbGetRecord(&pSaveState)) {
    if (wIndex == wNumber) {
      *ppRecord = (void *)pSaveState;
      return 1;
    }
    wIndex++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<SmbGetRecordByNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <SmbGetRecord@plt>
cmp    $0x0,%rax
je     1179 <SmbGetRecordByNumber+0x69>
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1168 <SmbGetRecordByNumber+0x58>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1180 <SmbGetRecordByNumber+0x70>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1130 <SmbGetRecordByNumber+0x20>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SmbGetRecordByNumber>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1030 <SmbGetRecord@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1162 <SmbGetRecordByNumber+0x52>
add    $0x1,%rbx
mov    %rsp,%rbp
nopl   0x0(%rax)
add    $0xffffffffffffffff,%rbx
je     1155 <SmbGetRecordByNumber+0x45>
mov    %rbp,%rdi
call   1030 <SmbGetRecord@plt>
test   %rax,%rax
jne    1140 <SmbGetRecordByNumber+0x30>
jmp    1162 <SmbGetRecordByNumber+0x52>
mov    (%rsp),%rax
mov    %rax,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @SmbGetRecordByNumber(i64 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
store i64 %0, i64* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i64 0, i64* %7
br label %8
8: ; preds = %19, %2
%9 = call i64 @SmbGetRecord(i32** %6)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i64, i64* %7
%13 = load i64, i64* %4
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32*, i32** %6
%17 = bitcast i32* %16 to i8*
%18 = load i8**, i8*** %5
store i8* %17, i8** %18
store i32 1, i32* %3
br label %23
19: ; preds = %11
%20 = load i64, i64* %7
%21 = add nsw i64 %20, 1
store i64 %21, i64* %7
br label %8
22: ; preds = %8
store i32 0, i32* %3
br label %23
23: ; preds = %22, %15
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @SmbGetRecordByNumber(i64 %0, i8** nocapture writeonly %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%5 = call i64 @SmbGetRecord(i32** %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %11
7: ; preds = %11
%8 = add nuw nsw i64 %12, 1
%9 = call i64 @SmbGetRecord(i32** %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %2, %7
%12 = phi i64 [ %8, %7 ], [ 0, %2 ]
%13 = icmp eq i64 %12, %0
br i1 %13, label %14, label %7
14: ; preds = %11
%15 = bitcast i32** %3 to i8**
%16 = load i8*, i8** %15
store i8* %16, i8** %1
br label %17
17: ; preds = %7, %2, %14
%18 = phi i32 [ 1, %14 ], [ 0, %2 ], [ 0, %7 ]
ret i32 %18
}