#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 drv_generic_serial_read(char *, int);
int /*<<< orphan*/ message(int, char *, int);
int strncmp(char const *, char const *, unsigned int const);
int /*<<< orphan*/ usleep(int);
int drv_PICGraphic_recv(char *dest, const unsigned int len,
                        const char *expect) {
  unsigned int bytes = 0;
  int status;
  while (bytes < len) {
    status = drv_generic_serial_read((char *)dest + bytes, 1);
    if (status == 1) {
      if (dest[bytes] != 0xa && dest[bytes] != 0xd) {
        if (dest[bytes] != '@') {
          bytes += status;
        }
      }
    } else {
      message(1, "error receiving response: %d", status);
      return status;
    }
    usleep(10000);
  }
  status = strncmp((const char *)dest, expect, len);
  if (!status) {
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<drv_PICGraphic_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1204 <drv_PICGraphic_recv+0xc4>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    %rax,%rdi
mov    $0x1,%esi
call   1050 <drv_generic_serial_read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jne    11d6 <drv_PICGraphic_recv+0x96>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11d1 <drv_PICGraphic_recv+0x91>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
je     11d1 <drv_PICGraphic_recv+0x91>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x40,%eax
je     11cc <drv_PICGraphic_recv+0x8c>
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11d1 <drv_PICGraphic_recv+0x91>
jmp    11f5 <drv_PICGraphic_recv+0xb5>
mov    -0x28(%rbp),%edx
mov    $0x1,%edi
lea    0xe1b(%rip),%rsi
call   1030 <message@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1234 <drv_PICGraphic_recv+0xf4>
mov    $0x2710,%edi
call   1060 <usleep@plt>
jmp    115a <drv_PICGraphic_recv+0x1a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncmp@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    122d <drv_PICGraphic_recv+0xed>
movl   $0x0,-0x4(%rbp)
jmp    1234 <drv_PICGraphic_recv+0xf4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drv_PICGraphic_recv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %esi,%r12d
mov    %rdi,%r15
test   %esi,%esi
je     11af <drv_PICGraphic_recv+0x6f>
xor    %r13d,%r13d
movabs $0x40000000000009,%r14
jmp    1183 <drv_PICGraphic_recv+0x43>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
mov    $0x2710,%edi
call   1060 <usleep@plt>
cmp    %r12d,%r13d
jae    11af <drv_PICGraphic_recv+0x6f>
mov    %r13d,%ebx
add    %r15,%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <drv_generic_serial_read@plt>
cmp    $0x1,%eax
jne    11c8 <drv_PICGraphic_recv+0x88>
movzbl (%rbx),%eax
add    $0xf6,%al
cmp    $0x36,%al
ja     1170 <drv_PICGraphic_recv+0x30>
movzbl %al,%eax
bt     %rax,%r14
jb     1174 <drv_PICGraphic_recv+0x34>
jmp    1170 <drv_PICGraphic_recv+0x30>
mov    %r15,%rdi
mov    (%rsp),%rsi
mov    %r12d,%edx
call   1040 <strncmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
jmp    11dd <drv_PICGraphic_recv+0x9d>
mov    %eax,%ebp
lea    0xe2f(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1030 <message@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"error receiving response: %d\00"
define i32 @drv_PICGraphic_recv(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 0, i32* %8
br label %10
10: ; preds = %56, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %58
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load i32, i32* %8
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = call i32 @drv_generic_serial_read(i8* %18, i32 1)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %52
22: ; preds = %14
%23 = load i8*, i8** %5
%24 = load i32, i32* %8
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 10
br i1 %29, label %30, label %51
30: ; preds = %22
%31 = load i8*, i8** %5
%32 = load i32, i32* %8
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 13
br i1 %37, label %38, label %51
38: ; preds = %30
%39 = load i8*, i8** %5
%40 = load i32, i32* %8
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 64
br i1 %45, label %46, label %50
46: ; preds = %38
%47 = load i32, i32* %9
%48 = load i32, i32* %8
%49 = add i32 %48, %47
store i32 %49, i32* %8
br label %50
50: ; preds = %46, %38
br label %51
51: ; preds = %50, %30, %22
br label %56
52: ; preds = %14
%53 = load i32, i32* %9
%54 = call i32 @message(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %9
store i32 %55, i32* %4
br label %67
56: ; preds = %51
%57 = call i32 @usleep(i32 10000)
br label %10
58: ; preds = %10
%59 = load i8*, i8** %5
%60 = load i8*, i8** %7
%61 = load i32, i32* %6
%62 = call i32 @strncmp(i8* %59, i8* %60, i32 %61)
store i32 %62, i32* %9
%63 = load i32, i32* %9
%64 = icmp ne i32 %63, 0
br i1 %64, label %66, label %65
65: ; preds = %58
store i32 0, i32* %4
br label %67
66: ; preds = %58
store i32 1, i32* %4
br label %67
67: ; preds = %66, %65, %52
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
@.str = [29 x i8] c"error receiving response: %d\00"
define i32 @drv_PICGraphic_recv(i8* %0, i32 %1, i8* %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %21, label %5
5: ; preds = %3, %17
%6 = phi i32 [ %18, %17 ], [ 0, %3 ]
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = tail call i32 @drv_generic_serial_read(i8* %8, i32 1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %5
%12 = load i8, i8* %8
switch i8 %12, label %13 [
i8 10, label %17
i8 13, label %17
i8 64, label %17
]
13: ; preds = %11
%14 = add nuw i32 %6, 1
br label %17
15: ; preds = %5
%16 = tail call i32 @message(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %25
17: ; preds = %11, %11, %11, %13
%18 = phi i32 [ %14, %13 ], [ %6, %11 ], [ %6, %11 ], [ %6, %11 ]
%19 = tail call i32 @usleep(i32 10000)
%20 = icmp ult i32 %18, %1
br i1 %20, label %5, label %21
21: ; preds = %17, %3
%22 = tail call i32 @strncmp(i8* %0, i8* %2, i32 %1)
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %21, %15
%26 = phi i32 [ %9, %15 ], [ %24, %21 ]
ret i32 %26
}