#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 parseLength(unsigned char *);
int /*<<< orphan*/ writeError(int, char *, char *, int);
int countResponses(int nReceiveBufferSize, unsigned char *bufReceive) {
  int i = 0;
  int nLength = 0;
  int nResponseCount = 0;
  for (i = 0; i < nReceiveBufferSize; i++) {
    if (bufReceive[i] == 0x30) {
      nLength = parseLength(&bufReceive[i]);
      if (nLength > 0) {
        writeError(10, "[%s] Located start of SNMP response (%d bytes).",
                   "snmp.mod", nLength);
        nResponseCount++;
        i += nLength;
      }
    }
  }
  return nResponseCount;
}


x86 assembly (clang, -O0):
<countResponses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ce <countResponses+0xae>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    11bb <countResponses+0x9b>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1030 <parseLength@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11b6 <countResponses+0x96>
mov    -0x18(%rbp),%ecx
mov    $0xa,%edi
lea    0xe68(%rip),%rsi
lea    0xe91(%rip),%rdx
call   1040 <writeError@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <countResponses+0x9b>
jmp    11c0 <countResponses+0xa0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <countResponses+0x2b>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countResponses>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    118f <countResponses+0x6f>
mov    %rsi,%rbx
mov    %edi,%r13d
xor    %r14d,%r14d
lea    0xef1(%rip),%r12
xor    %r15d,%r15d
jmp    1159 <countResponses+0x39>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r15d
cmp    %r13d,%r15d
jge    1192 <countResponses+0x72>
movslq %r15d,%rdi
cmpb   $0x30,(%rbx,%rdi,1)
jne    1150 <countResponses+0x30>
add    %rbx,%rdi
call   1030 <parseLength@plt>
test   %eax,%eax
jle    1150 <countResponses+0x30>
mov    %eax,%ebp
mov    $0xa,%edi
lea    0xe84(%rip),%rsi
mov    %r12,%rdx
mov    %eax,%ecx
call   1040 <writeError@plt>
add    $0x1,%r14d
add    %ebp,%r15d
jmp    1150 <countResponses+0x30>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"[%s] Located start of SNMP response (%d bytes).\00"
@.str.1 = [9 x i8] c"snmp.mod\00"
define i32 @countResponses(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %5
br label %8
8: ; preds = %38, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %41
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 48
br i1 %19, label %20, label %37
20: ; preds = %12
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = call i32 @parseLength(i8* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %20
%29 = load i32, i32* %6
%30 = call i32 @writeError(i32 10, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = add nsw i32 %34, %33
store i32 %35, i32* %5
br label %36
36: ; preds = %28, %20
br label %37
37: ; preds = %36, %12
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %8
41: ; preds = %8
%42 = load i32, i32* %7
ret i32 %42
}

LLVM IR (-O2):
@.str = [48 x i8] c"[%s] Located start of SNMP response (%d bytes).\00"
@.str.1 = [9 x i8] c"snmp.mod\00"
define i32 @countResponses(i32 %0, i8* %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %23
4: ; preds = %2, %18
%5 = phi i32 [ %20, %18 ], [ 0, %2 ]
%6 = phi i32 [ %21, %18 ], [ 0, %2 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 48
br i1 %10, label %11, label %18
11: ; preds = %4
%12 = tail call i32 @parseLength(i8* %8)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = tail call i32 @writeError(i32 10, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%16 = add nsw i32 %5, 1
%17 = add nsw i32 %12, %6
br label %18
18: ; preds = %4, %14, %11
%19 = phi i32 [ %17, %14 ], [ %6, %11 ], [ %6, %4 ]
%20 = phi i32 [ %16, %14 ], [ %5, %11 ], [ %5, %4 ]
%21 = add nsw i32 %19, 1
%22 = icmp slt i32 %21, %0
br i1 %22, label %4, label %23
23: ; preds = %18, %2
%24 = phi i32 [ 0, %2 ], [ %20, %18 ]
ret i32 %24
}