#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 scalar_t__ uint8_t;

/* Variables and functions */
scalar_t__ pdu_phone_is_packed(scalar_t__ *);
void pdu_phone_copy(uint8_t *in, uint8_t *out) {
  if (in == out)
    return;
  uint8_t eop = pdu_phone_is_packed(in) ? 0xFF : 0;
  while (*in != eop)
    *out++ = *in++;
  *out = eop;
}


x86 assembly (clang, -O0):
<pdu_phone_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1133 <pdu_phone_copy+0x23>
jmp    1198 <pdu_phone_copy+0x88>
mov    -0x8(%rbp),%rdi
call   1030 <pdu_phone_is_packed@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0xff,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
je     118d <pdu_phone_copy+0x7d>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,(%rax)
jmp    1153 <pdu_phone_copy+0x43>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdu_phone_copy>:
cmp    %rsi,%rdi
je     115d <pdu_phone_copy+0x4d>
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <pdu_phone_is_packed@plt>
test   %rax,%rax
mov    $0xff,%ecx
cmove  %rax,%rcx
mov    (%rbx),%rax
cmp    %rcx,%rax
je     1153 <pdu_phone_copy+0x43>
add    $0x8,%rbx
nopl   0x0(%rax)
mov    %rax,(%r14)
add    $0x8,%r14
mov    (%rbx),%rax
add    $0x8,%rbx
cmp    %rcx,%rax
jne    1140 <pdu_phone_copy+0x30>
mov    %rcx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @pdu_phone_copy(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca i64
store i64* %0, i64** %3
store i64* %1, i64** %4
%6 = load i64*, i64** %3
%7 = load i64*, i64** %4
%8 = icmp eq i64* %6, %7
br i1 %8, label %9, label %10
9: ; preds = %2
br label %31
10: ; preds = %2
%11 = load i64*, i64** %3
%12 = call i64 @pdu_phone_is_packed(i64* %11)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 255, i32 0
%16 = sext i32 %15 to i64
store i64 %16, i64* %5
br label %17
17: ; preds = %22, %10
%18 = load i64*, i64** %3
%19 = load i64, i64* %18
%20 = load i64, i64* %5
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i64*, i64** %3
%24 = getelementptr inbounds i64, i64* %23, i32 1
store i64* %24, i64** %3
%25 = load i64, i64* %23
%26 = load i64*, i64** %4
%27 = getelementptr inbounds i64, i64* %26, i32 1
store i64* %27, i64** %4
store i64 %25, i64* %26
br label %17
28: ; preds = %17
%29 = load i64, i64* %5
%30 = load i64*, i64** %4
store i64 %29, i64* %30
br label %31
31: ; preds = %28, %9
ret void
}

LLVM IR (-O2):
define void @pdu_phone_copy(i64* %0, i64* writeonly %1) {
%3 = icmp eq i64* %0, %1
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = tail call i64 @pdu_phone_is_packed(i64* %0)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i64 0, i64 255
%8 = load i64, i64* %0
%9 = icmp eq i64 %8, %7
br i1 %9, label %18, label %10
10: ; preds = %4, %10
%11 = phi i64 [ %16, %10 ], [ %8, %4 ]
%12 = phi i64* [ %14, %10 ], [ %0, %4 ]
%13 = phi i64* [ %15, %10 ], [ %1, %4 ]
%14 = getelementptr inbounds i64, i64* %12, i64 1
%15 = getelementptr inbounds i64, i64* %13, i64 1
store i64 %11, i64* %13
%16 = load i64, i64* %14
%17 = icmp eq i64 %16, %7
br i1 %17, label %18, label %10
18: ; preds = %10, %4
%19 = phi i64* [ %1, %4 ], [ %15, %10 ]
store i64 %7, i64* %19
br label %20
20: ; preds = %2, %18
ret void
}