#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 */

/* Variables and functions */
int /*<<< orphan*/ die(char *, char, ...);
int /*<<< orphan*/ errno;
int read(int, char *, int);
char strerror(int /*<<< orphan*/);
int write(int, char *, int);
void send_command(int fd, char cmd) {
  int rc;
  char c;
  rc = write(fd, &cmd, 1);
  if (rc < 0)
    die("write[%c]: %s\n", cmd, strerror(errno));
  if (rc != 1)
    die("write[%c]: unexected return value %d\n", cmd, rc);
  rc = read(fd, &c, 1);
  if (rc < 0)
    die("read[%c]: %s\n", cmd, strerror(errno));
  if (rc == 0)
    die("read[%c]: echo timed out\n", cmd);
  if (c != cmd)
    die("read[%c]: echo garbled: %c\n", cmd, c);
}


x86 assembly (clang, -O0):
<send_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    119c <send_command+0x5c>
mov    -0x5(%rbp),%al
mov    %al,-0xe(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %al,%cl
mov    -0xe(%rbp),%al
movsbl %cl,%edx
lea    0xe6e(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1050 <die@plt>
cmpl   $0x1,-0xc(%rbp)
je     11bd <send_command+0x7d>
mov    -0x5(%rbp),%al
mov    -0xc(%rbp),%edx
lea    0xe5c(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1050 <die@plt>
mov    -0x4(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1208 <send_command+0xc8>
mov    -0x5(%rbp),%al
mov    %al,-0xf(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %al,%cl
mov    -0xf(%rbp),%al
movsbl %cl,%edx
lea    0xe37(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1050 <die@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1224 <send_command+0xe4>
lea    0xe2a(%rip),%rdi
movsbl -0x5(%rbp),%esi
mov    $0x0,%al
call   1050 <die@plt>
movsbl -0xd(%rbp),%eax
movsbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
je     124c <send_command+0x10c>
mov    -0x5(%rbp),%al
movsbl -0xd(%rbp),%edx
lea    0xe1b(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1050 <die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_command>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %bl,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ebp
test   %eax,%eax
js     116d <send_command+0x2d>
cmp    $0x1,%ebp
jne    118f <send_command+0x4f>
jmp    11a2 <send_command+0x62>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
movsbl %al,%edx
movsbl %bl,%esi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <die@plt>
movsbl %bl,%esi
lea    0xe76(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <die@plt>
lea    0xe(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
js     11cd <send_command+0x8d>
jne    11ef <send_command+0xaf>
movsbl %bl,%esi
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <die@plt>
jmp    11ef <send_command+0xaf>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
movsbl %al,%edx
movsbl %bl,%esi
lea    0xe4d(%rip),%rdi
xor    %eax,%eax
call   1050 <die@plt>
movsbl 0xe(%rsp),%edx
cmp    %bl,%dl
jne    1201 <send_command+0xc1>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
movsbl %bl,%esi
lea    0xe52(%rip),%rdi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <die@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"write[%c]: %s\0A\00"
@errno = global i32 0
@.str.1 = [38 x i8] c"write[%c]: unexected return value %d\0A\00"
@.str.2 = [14 x i8] c"read[%c]: %s\0A\00"
@.str.3 = [26 x i8] c"read[%c]: echo timed out\0A\00"
@.str.4 = [28 x i8] c"read[%c]: echo garbled: %c\0A\00"
define void @send_command(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %3
store i8 %1, i8* %4
%7 = load i32, i32* %3
%8 = call i32 @write(i32 %7, i8* %4, i32 1)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8, i8* %4
%13 = load i32, i32* @errno
%14 = call signext i8 @strerror(i32 %13)
%15 = sext i8 %14 to i32
%16 = call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %12, i32 %15)
br label %17
17: ; preds = %11, %2
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i8, i8* %4
%22 = load i32, i32* %5
%23 = call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8 signext %21, i32 %22)
br label %24
24: ; preds = %20, %17
%25 = load i32, i32* %3
%26 = call i32 @read(i32 %25, i8* %6, i32 1)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i8, i8* %4
%31 = load i32, i32* @errno
%32 = call signext i8 @strerror(i32 %31)
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8 signext %30, i32 %33)
br label %35
35: ; preds = %29, %24
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i8, i8* %4
%40 = call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8 signext %39)
br label %41
41: ; preds = %38, %35
%42 = load i8, i8* %6
%43 = sext i8 %42 to i32
%44 = load i8, i8* %4
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %43, %45
br i1 %46, label %47, label %52
47: ; preds = %41
%48 = load i8, i8* %4
%49 = load i8, i8* %6
%50 = sext i8 %49 to i32
%51 = call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8 signext %48, i32 %50)
br label %52
52: ; preds = %47, %41
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"write[%c]: %s\0A\00"
@errno = global i32 0
@.str.1 = [38 x i8] c"write[%c]: unexected return value %d\0A\00"
@.str.2 = [14 x i8] c"read[%c]: %s\0A\00"
@.str.3 = [26 x i8] c"read[%c]: echo timed out\0A\00"
@.str.4 = [28 x i8] c"read[%c]: echo garbled: %c\0A\00"
define void @send_command(i32 %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca i8
store i8 %1, i8* %3
%5 = call i32 @write(i32 %0, i8* %3, i32 1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call signext i8 @strerror(i32 %8)
%10 = sext i8 %9 to i32
%11 = tail call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %1, i32 %10)
br label %14
12: ; preds = %2
%13 = icmp eq i32 %5, 1
br i1 %13, label %16, label %14
14: ; preds = %7, %12
%15 = tail call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8 signext %1, i32 %5)
br label %16
16: ; preds = %14, %12
%17 = call i32 @read(i32 %0, i8* %4, i32 1)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* @errno
%21 = tail call signext i8 @strerror(i32 %20)
%22 = sext i8 %21 to i32
%23 = tail call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8 signext %1, i32 %22)
br label %28
24: ; preds = %16
%25 = icmp eq i32 %17, 0
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = tail call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8 signext %1)
br label %28
28: ; preds = %19, %26, %24
%29 = load i8, i8* %4
%30 = icmp eq i8 %29, %1
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = sext i8 %29 to i32
%33 = tail call i32 (i8*, i8, ...) @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8 signext %1, i32 %32)
br label %34
34: ; preds = %31, %28
ret void
}