#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ xmodem_getc(int *);
int /*<<< orphan*/ xmodem_send_pkt(int const *, size_t, int);
int xmodem_send_pkt_with_retry(const uint8_t *data, size_t data_len,
                               uint8_t pkt_no) {
  uint8_t retransmit = (3);
  uint8_t rsp;
  ;
  while (retransmit--) {
    xmodem_send_pkt(data, data_len, pkt_no);
    rsp = (0xFF);
    xmodem_getc(&rsp);
    if (rsp == (0x06)) {
      ;
      return 0;
    }

    ;
  }
  return -1;
}


x86 assembly (clang, -O0):
<xmodem_send_pkt_with_retry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x3,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
je     1189 <xmodem_send_pkt_with_retry+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <xmodem_send_pkt@plt>
movl   $0xff,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <xmodem_getc@plt>
cmpl   $0x6,-0x24(%rbp)
jne    1184 <xmodem_send_pkt_with_retry+0x64>
movl   $0x0,-0x4(%rbp)
jmp    1190 <xmodem_send_pkt_with_retry+0x70>
jmp    113a <xmodem_send_pkt_with_retry+0x1a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmodem_send_pkt_with_retry>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1030 <xmodem_send_pkt@plt>
movl   $0xff,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <xmodem_getc@plt>
xor    %ebx,%ebx
cmpl   $0x6,0x4(%rsp)
je     11a3 <xmodem_send_pkt_with_retry+0x83>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <xmodem_send_pkt@plt>
movl   $0xff,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <xmodem_getc@plt>
cmpl   $0x6,0x4(%rsp)
je     11a3 <xmodem_send_pkt_with_retry+0x83>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <xmodem_send_pkt@plt>
movl   $0xff,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <xmodem_getc@plt>
xor    %ebx,%ebx
cmpl   $0x6,0x4(%rsp)
setne  %bl
neg    %ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @xmodem_send_pkt_with_retry(i32* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32 3, i32* %8
br label %10
10: ; preds = %23, %3
%11 = load i32, i32* %8
%12 = add nsw i32 %11, -1
store i32 %12, i32* %8
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32*, i32** %5
%16 = load i64, i64* %6
%17 = load i32, i32* %7
%18 = call i32 @xmodem_send_pkt(i32* %15, i64 %16, i32 %17)
store i32 255, i32* %9
%19 = call i32 @xmodem_getc(i32* %9)
%20 = load i32, i32* %9
%21 = icmp eq i32 %20, 6
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 0, i32* %4
br label %25
23: ; preds = %14
br label %10
24: ; preds = %10
store i32 -1, i32* %4
br label %25
25: ; preds = %24, %22
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
define i32 @xmodem_send_pkt_with_retry(i32* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @xmodem_send_pkt(i32* %0, i64 %1, i32 %2)
store i32 255, i32* %4
%7 = call i32 @xmodem_getc(i32* %4)
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 6
br i1 %9, label %21, label %10
10: ; preds = %3
%11 = call i32 @xmodem_send_pkt(i32* %0, i64 %1, i32 %2)
store i32 255, i32* %4
%12 = call i32 @xmodem_getc(i32* %4)
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 6
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = call i32 @xmodem_send_pkt(i32* %0, i64 %1, i32 %2)
store i32 255, i32* %4
%17 = call i32 @xmodem_getc(i32* %4)
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 6
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %15, %10, %3
%22 = phi i32 [ 0, %3 ], [ 0, %10 ], [ %20, %15 ]
ret i32 %22
}