#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 /*<<< orphan*/ cmd;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int);
int send_char(int, char);
int send_echo(int fd) {
  int i, rc;
  char cmd[] = {0x00, 0x04, 0x41};
  for (i = 0; i < sizeof(cmd); i++) {
    rc = send_char(fd, cmd[i]);
    if (rc == -1)
      return rc;
  }
  printf("send_echo: Writing %ld bytes to FD[%d]\n\r", sizeof(cmd), fd);
  return 1;
}


x86 assembly (clang, -O0):
<send_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0xece(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xec6(%rip),%al
mov    %al,-0x11(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x3,%rax
jae    1190 <send_echo+0x70>
mov    -0x8(%rbp),%edi
movslq -0xc(%rbp),%rax
movsbl -0x13(%rbp,%rax,1),%esi
call   1040 <send_char@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    117d <send_echo+0x5d>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <send_echo+0x8b>
jmp    1182 <send_echo+0x62>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <send_echo+0x26>
mov    -0x8(%rbp),%edx
lea    0xe69(%rip),%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_echo>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %esi,%esi
call   1040 <send_char@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     1170 <send_echo+0x50>
mov    %ebx,%edi
mov    $0x4,%esi
call   1040 <send_char@plt>
cmp    $0xffffffff,%eax
je     1170 <send_echo+0x50>
mov    %ebx,%edi
mov    $0x41,%esi
call   1040 <send_char@plt>
cmp    $0xffffffff,%eax
je     1170 <send_echo+0x50>
lea    0xea1(%rip),%rdi
mov    $0x3,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.send_echo.cmd = [3 x i8] c"\00\04A"
@.str = [41 x i8] c"send_echo: Writing %ld bytes to FD[%d]\0A\0D\00"
define i32 @send_echo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [3 x i8]
store i32 %0, i32* %3
%7 = bitcast [3 x i8]* %6 to i8*
store i32 0, i32* %4
br label %8
8: ; preds = %24, %1
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = icmp ult i64 %10, 3
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = call i32 @send_char(i32 %13, i8 signext %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = load i32, i32* %5
store i32 %22, i32* %2
br label %30
23: ; preds = %12
br label %24
24: ; preds = %23
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %8
27: ; preds = %8
%28 = load i32, i32* %3
%29 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 3, i32 %28)
store i32 1, i32* %2
br label %30
30: ; preds = %27, %21
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [41 x i8] c"send_echo: Writing %ld bytes to FD[%d]\0A\0D\00"
define i32 @send_echo(i32 %0) {
%2 = tail call i32 @send_char(i32 %0, i8 signext 0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @send_char(i32 %0, i8 signext 4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i32 @send_char(i32 %0, i8 signext 65)
%9 = icmp eq i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 3, i32 %0)
br label %12
12: ; preds = %1, %4, %7, %10
%13 = phi i32 [ 1, %10 ], [ -1, %7 ], [ -1, %4 ], [ -1, %1 ]
ret i32 %13
}