#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 send_char(int, char);
int send_open(int fd) {
  int i, rc;
  char cmd[] = {0x00, 0x02};
  for (i = 0; i < sizeof(cmd); i++) {
    rc = send_char(fd, cmd[i]);
    if (rc == -1)
      return rc;
  }
  printf("send_open: Writing 2 bytes to FD[%d]\n\r", fd);
  return 1;
}


x86 assembly (clang, -O0):
<send_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0xece(%rip),%ax
mov    %ax,-0x12(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x2,%rax
jae    1187 <send_open+0x67>
mov    -0x8(%rbp),%edi
movslq -0xc(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%esi
call   1040 <send_char@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1174 <send_open+0x54>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119d <send_open+0x7d>
jmp    1179 <send_open+0x59>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113d <send_open+0x1d>
mov    -0x8(%rbp),%esi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_open>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %esi,%esi
call   1040 <send_char@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     115a <send_open+0x3a>
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <send_char@plt>
cmp    $0xffffffff,%eax
je     115a <send_open+0x3a>
lea    0xeb2(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.send_open.cmd = [2 x i8] c"\00\02"
@.str = [39 x i8] c"send_open: Writing 2 bytes to FD[%d]\0A\0D\00"
define i32 @send_open(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i8]
store i32 %0, i32* %3
%7 = bitcast [2 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, 2
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 [2 x i8], [2 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 ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), 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 = [39 x i8] c"send_open: Writing 2 bytes to FD[%d]\0A\0D\00"
define i32 @send_open(i32 %0) {
%2 = tail call i32 @send_char(i32 %0, i8 signext 0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i32 @send_char(i32 %0, i8 signext 2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %9
9: ; preds = %1, %4, %7
%10 = phi i32 [ 1, %7 ], [ -1, %4 ], [ -1, %1 ]
ret i32 %10
}