#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 */
struct usb_spca50x {
  int dummy;
};
struct spca50x_frame {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ PDEBUG(int, char *, int);
int cx11646_sofdetect(struct usb_spca50x *spca50x, struct spca50x_frame *frame,
                      unsigned char *cdata, int *iPix, int seqnum,
                      int *datalength) {
  *iPix = 0;
  if (cdata[0] == 0xFF && cdata[1] == 0xD8) {
    *iPix = 2;
    *datalength -= *iPix;
    PDEBUG(5, "Cx11646 header packet found datalength %d !!", *datalength);
    return 0;
  } else
    return (seqnum + 1);
}


x86 assembly (clang, -O0):
<cx11646_sofdetect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    119c <cx11646_sofdetect+0x8c>
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0xd8,%eax
jne    119c <cx11646_sofdetect+0x8c>
mov    -0x28(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
mov    $0x5,%edi
lea    0xe75(%rip),%rsi
call   1030 <PDEBUG@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <cx11646_sofdetect+0x95>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cx11646_sofdetect>:
push   %rax
mov    %r8d,%eax
movl   $0x0,(%rcx)
cmpb   $0xff,(%rdx)
jne    1149 <cx11646_sofdetect+0x39>
cmpb   $0xd8,0x1(%rdx)
jne    1149 <cx11646_sofdetect+0x39>
movl   $0x2,(%rcx)
mov    (%r9),%edx
add    $0xfffffffe,%edx
mov    %edx,(%r9)
lea    0xec5(%rip),%rsi
mov    $0x5,%edi
call   1030 <PDEBUG@plt>
xor    %eax,%eax
pop    %rcx
ret
add    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.usb_spca50x = type { i32 }
%struct.spca50x_frame = type { i32 }
@.str = [45 x i8] c"Cx11646 header packet found datalength %d !!\00"
define i32 @cx11646_sofdetect(%struct.usb_spca50x* %0, %struct.spca50x_frame* %1, i8* %2, i32* %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca %struct.usb_spca50x*
%9 = alloca %struct.spca50x_frame*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32*
store %struct.usb_spca50x* %0, %struct.usb_spca50x** %8
store %struct.spca50x_frame* %1, %struct.spca50x_frame** %9
store i8* %2, i8** %10
store i32* %3, i32** %11
store i32 %4, i32* %12
store i32* %5, i32** %13
%14 = load i32*, i32** %11
store i32 0, i32* %14
%15 = load i8*, i8** %10
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 255
br i1 %19, label %20, label %36
20: ; preds = %6
%21 = load i8*, i8** %10
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %24, 216
br i1 %25, label %26, label %36
26: ; preds = %20
%27 = load i32*, i32** %11
store i32 2, i32* %27
%28 = load i32*, i32** %11
%29 = load i32, i32* %28
%30 = load i32*, i32** %13
%31 = load i32, i32* %30
%32 = sub nsw i32 %31, %29
store i32 %32, i32* %30
%33 = load i32*, i32** %13
%34 = load i32, i32* %33
%35 = call i32 @PDEBUG(i32 5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %34)
store i32 0, i32* %7
br label %39
36: ; preds = %20, %6
%37 = load i32, i32* %12
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %39
39: ; preds = %36, %26
%40 = load i32, i32* %7
ret i32 %40
}

LLVM IR (-O2):
%struct.usb_spca50x = type { i32 }
%struct.spca50x_frame = type { i32 }
@.str = [45 x i8] c"Cx11646 header packet found datalength %d !!\00"
define i32 @cx11646_sofdetect(%struct.usb_spca50x* nocapture readnone %0, %struct.spca50x_frame* nocapture readnone %1, i8* nocapture %2, i32* nocapture writeonly %3, i32 %4, i32* nocapture %5) {
store i32 0, i32* %3
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, -1
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %2, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, -40
br i1 %12, label %13, label %17
13: ; preds = %9
store i32 2, i32* %3
%14 = load i32, i32* %5
%15 = add nsw i32 %14, -2
store i32 %15, i32* %5
%16 = tail call i32 @PDEBUG(i32 5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %19
17: ; preds = %9, %6
%18 = add nsw i32 %4, 1
br label %19
19: ; preds = %17, %13
%20 = phi i32 [ 0, %13 ], [ %18, %17 ]
ret i32 %20
}