#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 */
short alpar_recv(int, unsigned char *, unsigned char *, unsigned char **,
                 unsigned char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned char, ...);
void irecv(int fd) {
  unsigned char command;
  unsigned char *data;
  short int length;
  unsigned char lrc;
  unsigned char ack;
  length = alpar_recv(fd, &ack, &command, &data, &lrc);
  if (length == -1) {
    perror("receieve failure");
    return;
  }
  printf("command=%x,length=%hx\n", command, length);
  if (length) {
    int i;
    for (i = 0; i < length; i++)
      printf("data[%d]=%u(0x%x)(\'%c\')\n", i, (unsigned char)data[i],
             (unsigned char)data[i], (unsigned char)data[i]);
    free(data);
  }
  printf("lrc=%u\n", lrc);
}


x86 assembly (clang, -O0):
<irecv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0x5(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x13(%rbp),%r8
call   1060 <alpar_recv@plt>
mov    %ax,-0x12(%rbp)
movswl -0x12(%rbp),%eax
cmp    $0xffffffff,%eax
jne    1185 <irecv+0x45>
lea    0xe85(%rip),%rdi
call   1050 <perror@plt>
jmp    1220 <irecv+0xe0>
mov    -0x5(%rbp),%al
movswl -0x12(%rbp),%edx
lea    0xe7e(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
cmpw   $0x0,-0x12(%rbp)
je     120e <irecv+0xce>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movswl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jge    1205 <irecv+0xc5>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movzbl (%rcx,%rdx,1),%edx
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rsi
movzbl (%rcx,%rsi,1),%ecx
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rdi
movzbl (%rsi,%rdi,1),%r8d
lea    0xe3b(%rip),%rdi
movzbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11af <irecv+0x6f>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe2c(%rip),%rdi
movzbl -0x13(%rbp),%esi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irecv>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x7(%rsp),%rsi
lea    0x6(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x5(%rsp),%r8
call   1060 <alpar_recv@plt>
cmp    $0xffff,%ax
je     11ea <irecv+0xaa>
mov    %eax,%ebp
movswl %ax,%ebx
movzbl 0x6(%rsp),%esi
lea    0xe95(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %bp,%bp
je     11ce <irecv+0x8e>
jle    11c4 <irecv+0x84>
mov    %ebx,%ebp
lea    0xe93(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
movzbl (%rax,%rbx,1),%ecx
movzbl %bl,%esi
mov    %r14,%rdi
mov    %ecx,%edx
mov    %ecx,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <irecv+0x60>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
movzbl 0x5(%rsp),%esi
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe0f(%rip),%rdi
call   1050 <perror@plt>
jmp    11e1 <irecv+0xa1>

LLVM IR (-O0):
@.str = [17 x i8] c"receieve failure\00"
@.str.1 = [23 x i8] c"command=%x,length=%hx\0A\00"
@.str.2 = [25 x i8] c"data[%d]=%u(0x%x)('%c')\0A\00"
@.str.3 = [8 x i8] c"lrc=%u\0A\00"
define void @irecv(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
store i32 %0, i32* %2
%9 = load i32, i32* %2
%10 = call signext i16 @alpar_recv(i32 %9, i8* %7, i8* %3, i8** %4, i8* %6)
store i16 %10, i16* %5
%11 = load i16, i16* %5
%12 = sext i16 %11 to i32
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %60
16: ; preds = %1
%17 = load i8, i8* %3
%18 = load i16, i16* %5
%19 = sext i16 %18 to i32
%20 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %17, i32 %19)
%21 = load i16, i16* %5
%22 = icmp ne i16 %21, 0
br i1 %22, label %23, label %57
23: ; preds = %16
store i32 0, i32* %8
br label %24
24: ; preds = %51, %23
%25 = load i32, i32* %8
%26 = load i16, i16* %5
%27 = sext i16 %26 to i32
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %54
29: ; preds = %24
%30 = load i32, i32* %8
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %4
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = load i8*, i8** %4
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = load i8*, i8** %4
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %31, i32 %37, i32 %43, i32 %49)
br label %51
51: ; preds = %29
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %24
54: ; preds = %24
%55 = load i8*, i8** %4
%56 = call i32 @free(i8* %55)
br label %57
57: ; preds = %54, %16
%58 = load i8, i8* %6
%59 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %58)
br label %60
60: ; preds = %57, %14
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"receieve failure\00"
@.str.1 = [23 x i8] c"command=%x,length=%hx\0A\00"
@.str.2 = [25 x i8] c"data[%d]=%u(0x%x)('%c')\0A\00"
@.str.3 = [8 x i8] c"lrc=%u\0A\00"
define void @irecv(i32 %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = bitcast i8** %3 to i8*
%7 = call signext i16 @alpar_recv(i32 %0, i8* %5, i8* %2, i8** %3, i8* %4)
%8 = sext i16 %7 to i32
%9 = icmp eq i16 %7, -1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %36
12: ; preds = %1
%13 = load i8, i8* %2
%14 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %13, i32 %8)
%15 = icmp eq i16 %7, 0
br i1 %15, label %33, label %16
16: ; preds = %12
%17 = icmp sgt i16 %7, 0
br i1 %17, label %18, label %30
18: ; preds = %16
%19 = zext i32 %8 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %28, %20 ]
%22 = trunc i64 %21 to i8
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 %21
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %22, i32 %26, i32 %26, i32 %26)
%28 = add nuw nsw i64 %21, 1
%29 = icmp eq i64 %28, %19
br i1 %29, label %30, label %20
30: ; preds = %20, %16
%31 = load i8*, i8** %3
%32 = call i32 @free(i8* %31)
br label %33
33: ; preds = %30, %12
%34 = load i8, i8* %4
%35 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %34)
br label %36
36: ; preds = %33, %10
ret void
}