#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 *, unsigned char, ...);
int Et_sofdetect(struct usb_spca50x *spca50x, struct spca50x_frame *frame,
                 unsigned char *cdata, int *iPix, int seqnum, int *datalength) {
  int seqframe;
  seqframe = cdata[0] & 0x3f;
  *datalength = (int)(((cdata[0] & 0xc0) << 2) | cdata[1]);
  if (seqframe == 0x3f) {
    PDEBUG(5, "Etoms header packet found datalength %d !!", *datalength);
    PDEBUG(5, "Etoms G %d R %d G %d B %d", cdata[2], cdata[3], cdata[4],
           cdata[5]);
    *iPix = 30;
    return 0;
  } else {
    if (*datalength) {
      *iPix = 8;
      return (seqnum + 1);
    } else {
      return -1;
    }
  }
}


x86 assembly (clang, -O0):
<Et_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    -0x20(%rbp),%rax
movzbl (%rax),%eax
and    $0x3f,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%ecx
and    $0xc0,%ecx
shl    $0x2,%ecx
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
or     %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x3f,-0x3c(%rbp)
jne    11d0 <Et_sofdetect+0xc0>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    $0x5,%edi
lea    0xe87(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1030 <PDEBUG@plt>
mov    -0x20(%rbp),%rax
mov    0x2(%rax),%al
mov    -0x20(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
mov    -0x20(%rbp),%rdx
movzbl 0x4(%rdx),%r8d
mov    -0x20(%rbp),%rdx
movzbl 0x5(%rdx),%r9d
mov    $0x5,%edi
lea    0xe7b(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1030 <PDEBUG@plt>
mov    -0x28(%rbp),%rax
movl   $0x1e,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11fc <Et_sofdetect+0xec>
mov    -0x38(%rbp),%rax
cmpl   $0x0,(%rax)
je     11f5 <Et_sofdetect+0xe5>
mov    -0x28(%rbp),%rax
movl   $0x8,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11fc <Et_sofdetect+0xec>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Et_sofdetect>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
movzbl (%rdx),%edx
mov    %edx,%ecx
and    $0xffffffc0,%ecx
movzbl 0x1(%rbx),%eax
lea    (%rax,%rcx,4),%ecx
mov    %ecx,(%r9)
not    %edx
test   $0x3f,%dl
jne    1179 <Et_sofdetect+0x69>
movzbl %al,%edx
lea    0xec3(%rip),%rsi
xor    %ebp,%ebp
mov    $0x5,%edi
xor    %eax,%eax
call   1030 <PDEBUG@plt>
movzbl 0x2(%rbx),%edx
movzbl 0x3(%rbx),%ecx
movzbl 0x4(%rbx),%r8d
movzbl 0x5(%rbx),%r9d
lea    0xec7(%rip),%rsi
mov    $0x5,%edi
xor    %eax,%eax
call   1030 <PDEBUG@plt>
movl   $0x1e,(%r14)
jmp    1191 <Et_sofdetect+0x81>
test   %ecx,%ecx
je     118c <Et_sofdetect+0x7c>
mov    %r8d,%ebp
movl   $0x8,(%r14)
add    $0x1,%ebp
jmp    1191 <Et_sofdetect+0x81>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.usb_spca50x = type { i32 }
%struct.spca50x_frame = type { i32 }
@.str = [43 x i8] c"Etoms header packet found datalength %d !!\00"
@.str.1 = [26 x i8] c"Etoms G %d R %d G %d B %d\00"
define i32 @Et_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*
%14 = 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
%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 = and i32 %18, 63
store i32 %19, i32* %14
%20 = load i8*, i8** %10
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = and i32 %23, 192
%25 = shl i32 %24, 2
%26 = load i8*, i8** %10
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = or i32 %25, %29
%31 = load i32*, i32** %13
store i32 %30, i32* %31
%32 = load i32, i32* %14
%33 = icmp eq i32 %32, 63
br i1 %33, label %34, label %56
34: ; preds = %6
%35 = load i32*, i32** %13
%36 = load i32, i32* %35
%37 = trunc i32 %36 to i8
%38 = call i32 (i32, i8*, i8, ...) @PDEBUG(i32 5, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8 zeroext %37)
%39 = load i8*, i8** %10
%40 = getelementptr inbounds i8, i8* %39, i64 2
%41 = load i8, i8* %40
%42 = load i8*, i8** %10
%43 = getelementptr inbounds i8, i8* %42, i64 3
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = load i8*, i8** %10
%47 = getelementptr inbounds i8, i8* %46, i64 4
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = load i8*, i8** %10
%51 = getelementptr inbounds i8, i8* %50, i64 5
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = call i32 (i32, i8*, i8, ...) @PDEBUG(i32 5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %41, i32 %45, i32 %49, i32 %53)
%55 = load i32*, i32** %11
store i32 30, i32* %55
store i32 0, i32* %7
br label %65
56: ; preds = %6
%57 = load i32*, i32** %13
%58 = load i32, i32* %57
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = load i32*, i32** %11
store i32 8, i32* %61
%62 = load i32, i32* %12
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %65
64: ; preds = %56
store i32 -1, i32* %7
br label %65
65: ; preds = %64, %60, %34
%66 = load i32, i32* %7
ret i32 %66
}

LLVM IR (-O2):
%struct.usb_spca50x = type { i32 }
%struct.spca50x_frame = type { i32 }
@.str = [43 x i8] c"Etoms header packet found datalength %d !!\00"
@.str.1 = [26 x i8] c"Etoms G %d R %d G %d B %d\00"
define i32 @Et_sofdetect(%struct.usb_spca50x* nocapture readnone %0, %struct.spca50x_frame* nocapture readnone %1, i8* nocapture %2, i32* nocapture writeonly %3, i32 %4, i32* nocapture writeonly %5) {
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = and i32 %8, 63
%10 = shl nuw nsw i32 %8, 2
%11 = and i32 %10, 768
%12 = getelementptr inbounds i8, i8* %2, i64 1
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = or i32 %11, %14
store i32 %15, i32* %5
%16 = icmp eq i32 %9, 63
br i1 %16, label %17, label %31
17: ; preds = %6
%18 = tail call i32 (i32, i8*, i8, ...) @PDEBUG(i32 5, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8 zeroext %13)
%19 = getelementptr inbounds i8, i8* %2, i64 2
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8, i8* %2, i64 3
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = getelementptr inbounds i8, i8* %2, i64 4
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = getelementptr inbounds i8, i8* %2, i64 5
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = tail call i32 (i32, i8*, i8, ...) @PDEBUG(i32 5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %20, i32 %23, i32 %26, i32 %29)
store i32 30, i32* %3
br label %35
31: ; preds = %6
%32 = icmp eq i32 %15, 0
br i1 %32, label %35, label %33
33: ; preds = %31
store i32 8, i32* %3
%34 = add nsw i32 %4, 1
br label %35
35: ; preds = %31, %33, %17
%36 = phi i32 [ 0, %17 ], [ %34, %33 ], [ -1, %31 ]
ret i32 %36
}