#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 sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int sendto(int, char *, int, int, struct sockaddr const *, int /*<<< orphan*/);
ssize_t send_motion_line(int sockfd, const void *buf, size_t len, int flags,
                         const struct sockaddr *dest_addr, socklen_t addrlen,
                         int format) {
  ssize_t size;
  switch (format) {
  default:
  case 0:
    if ((size = sendto(sockfd, buf, len, flags, dest_addr, addrlen)) == -1)
      return -1;
    break;
  case 1:
    if ((size = sendto(sockfd, "0 Avatarname ", sizeof("0 Avatarname "), flags,
                       dest_addr, addrlen)) == -1)
      return -1;
    if ((size = sendto(sockfd, buf, len - 1, flags, dest_addr, addrlen)) == -1)
      return -1;
    if ((size = sendto(sockfd, " ||\r\n", sizeof(" ||\r\n"), flags, dest_addr,
                       addrlen)) == -1)
      return -1;
    break;
  }
  return size;
}


x86 assembly (clang, -O0):
<send_motion_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     115a <send_motion_line+0x4a>
jmp    1144 <send_motion_line+0x34>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1194 <send_motion_line+0x84>
jmp    1155 <send_motion_line+0x45>
jmp    115a <send_motion_line+0x4a>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
call   1030 <sendto@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    118f <send_motion_line+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <send_motion_line+0x136>
jmp    1240 <send_motion_line+0x130>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
lea    0xe57(%rip),%rsi
mov    $0xe,%edx
call   1030 <sendto@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    11cb <send_motion_line+0xbb>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <send_motion_line+0x136>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%edx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
call   1030 <sendto@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    1204 <send_motion_line+0xf4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <send_motion_line+0x136>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
lea    0xdf5(%rip),%rsi
mov    $0x6,%edx
call   1030 <sendto@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    123b <send_motion_line+0x12b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <send_motion_line+0x136>
jmp    1240 <send_motion_line+0x130>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_motion_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8,%r12
mov    %ecx,%r13d
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %edi,%ebx
cmpl   $0x1,0x40(%rsp)
jne    119e <send_motion_line+0x8e>
lea    0xec6(%rip),%rsi
mov    %ebx,%edi
mov    $0xe,%edx
mov    %r13d,%ecx
mov    %r12,%r8
mov    %r14d,%r9d
call   1030 <sendto@plt>
mov    $0xffffffff,%ecx
cmp    $0xffffffff,%eax
je     11c1 <send_motion_line+0xb1>
add    $0xffffffff,%ebp
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %r12,%r8
mov    %r14d,%r9d
call   1030 <sendto@plt>
cmp    $0xffffffff,%eax
je     11bc <send_motion_line+0xac>
lea    0xe91(%rip),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
mov    %r13d,%ecx
mov    %r12,%r8
mov    %r14d,%r9d
call   1030 <sendto@plt>
cmp    $0xffffffff,%eax
mov    $0xffffffff,%ecx
jne    11b8 <send_motion_line+0xa8>
jmp    11c1 <send_motion_line+0xb1>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %r12,%r8
mov    %r14d,%r9d
call   1030 <sendto@plt>
cmp    $0xffffffff,%eax
je     11bc <send_motion_line+0xac>
mov    %eax,%ecx
jmp    11c1 <send_motion_line+0xb1>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"0 Avatarname \00"
@.str.1 = [6 x i8] c" ||\0D\0A\00"
define i32 @send_motion_line(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca %struct.sockaddr*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %9
store i8* %1, i8** %10
store i64 %2, i64* %11
store i32 %3, i32* %12
store %struct.sockaddr* %4, %struct.sockaddr** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
%17 = load i32, i32* %15
switch i32 %17, label %18 [
i32 0, label %19
i32 1, label %31
]
18: ; preds = %7
br label %19
19: ; preds = %7, %18
%20 = load i32, i32* %9
%21 = load i8*, i8** %10
%22 = load i64, i64* %11
%23 = trunc i64 %22 to i32
%24 = load i32, i32* %12
%25 = load %struct.sockaddr*, %struct.sockaddr** %13
%26 = load i32, i32* %14
%27 = call i32 @sendto(i32 %20, i8* %21, i32 %23, i32 %24, %struct.sockaddr* %25, i32 %26)
store i32 %27, i32* %16
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %19
store i32 -1, i32* %8
br label %62
30: ; preds = %19
br label %60
31: ; preds = %7
%32 = load i32, i32* %9
%33 = load i32, i32* %12
%34 = load %struct.sockaddr*, %struct.sockaddr** %13
%35 = load i32, i32* %14
%36 = call i32 @sendto(i32 %32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 14, i32 %33, %struct.sockaddr* %34, i32 %35)
store i32 %36, i32* %16
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %39
38: ; preds = %31
store i32 -1, i32* %8
br label %62
39: ; preds = %31
%40 = load i32, i32* %9
%41 = load i8*, i8** %10
%42 = load i64, i64* %11
%43 = sub i64 %42, 1
%44 = trunc i64 %43 to i32
%45 = load i32, i32* %12
%46 = load %struct.sockaddr*, %struct.sockaddr** %13
%47 = load i32, i32* %14
%48 = call i32 @sendto(i32 %40, i8* %41, i32 %44, i32 %45, %struct.sockaddr* %46, i32 %47)
store i32 %48, i32* %16
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %51
50: ; preds = %39
store i32 -1, i32* %8
br label %62
51: ; preds = %39
%52 = load i32, i32* %9
%53 = load i32, i32* %12
%54 = load %struct.sockaddr*, %struct.sockaddr** %13
%55 = load i32, i32* %14
%56 = call i32 @sendto(i32 %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6, i32 %53, %struct.sockaddr* %54, i32 %55)
store i32 %56, i32* %16
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %59
58: ; preds = %51
store i32 -1, i32* %8
br label %62
59: ; preds = %51
br label %60
60: ; preds = %59, %30
%61 = load i32, i32* %16
store i32 %61, i32* %8
br label %62
62: ; preds = %60, %58, %50, %38, %29
%63 = load i32, i32* %8
ret i32 %63
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"0 Avatarname \00"
@.str.1 = [6 x i8] c" ||\0D\0A\00"
define i32 @send_motion_line(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32 %5, i32 %6) {
%8 = icmp eq i32 %6, 1
br i1 %8, label %13, label %9
9: ; preds = %7
%10 = trunc i64 %2 to i32
%11 = tail call i32 @sendto(i32 %0, i8* %1, i32 %10, i32 %3, %struct.sockaddr* %4, i32 %5)
%12 = icmp eq i32 %11, -1
br i1 %12, label %26, label %24
13: ; preds = %7
%14 = tail call i32 @sendto(i32 %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 14, i32 %3, %struct.sockaddr* %4, i32 %5)
%15 = icmp eq i32 %14, -1
br i1 %15, label %26, label %16
16: ; preds = %13
%17 = trunc i64 %2 to i32
%18 = add i32 %17, -1
%19 = tail call i32 @sendto(i32 %0, i8* %1, i32 %18, i32 %3, %struct.sockaddr* %4, i32 %5)
%20 = icmp eq i32 %19, -1
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = tail call i32 @sendto(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6, i32 %3, %struct.sockaddr* %4, i32 %5)
%23 = icmp eq i32 %22, -1
br i1 %23, label %26, label %24
24: ; preds = %21, %9
%25 = phi i32 [ %22, %21 ], [ %11, %9 ]
br label %26
26: ; preds = %21, %16, %13, %9, %24
%27 = phi i32 [ %25, %24 ], [ -1, %9 ], [ -1, %13 ], [ -1, %16 ], [ -1, %21 ]
ret i32 %27
}