#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*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ write(int, int *, int);
int send_char(int fd, int c) {
  int rc;
  rc = (int)write(fd, &c, 1);
  if (rc == -1) {
    perror("send_char: Error writing to usb serial\n");
    return -1;
  }
  if (rc != 1) {
    printf("send_char: Write error: invalid number of characters written %d\n",
           rc);
    return -1;
  }
  printf("send_char: wrote %0x\r\n", c);
  return rc;
}


x86 assembly (clang, -O0):
<send_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1174 <send_char+0x44>
lea    0xe9d(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <send_char+0x7e>
cmpl   $0x1,-0x10(%rbp)
je     1199 <send_char+0x69>
mov    -0x10(%rbp),%esi
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <send_char+0x7e>
mov    -0xc(%rbp),%esi
lea    0xec6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_char>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %esi,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x1,%ebx
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     116c <send_char+0x3c>
cmp    $0xffffffff,%eax
je     1183 <send_char+0x53>
lea    0xeca(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    117a <send_char+0x4a>
lea    0xef6(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe76(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    117a <send_char+0x4a>

LLVM IR (-O0):
@.str = [40 x i8] c"send_char: Error writing to usb serial\0A\00"
@.str.1 = [65 x i8] c"send_char: Write error: invalid number of characters written %d\0A\00"
@.str.2 = [23 x i8] c"send_char: wrote %0x\0D\0A\00"
define i32 @send_char(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = call i64 @write(i32 %7, i32* %5, i32 1)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %24
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %6
%19 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i32 %18)
store i32 -1, i32* %3
br label %24
20: ; preds = %14
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %6
store i32 %23, i32* %3
br label %24
24: ; preds = %20, %17, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [40 x i8] c"send_char: Error writing to usb serial\0A\00"
@.str.1 = [65 x i8] c"send_char: Write error: invalid number of characters written %d\0A\00"
@.str.2 = [23 x i8] c"send_char: wrote %0x\0D\0A\00"
define i32 @send_char(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = call i64 @write(i32 %0, i32* %3, i32 1)
%5 = trunc i64 %4 to i32
switch i32 %5, label %8 [
i32 -1, label %6
i32 1, label %10
]
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %12
8: ; preds = %2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %12
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %12
12: ; preds = %10, %8, %6
%13 = phi i32 [ -1, %6 ], [ -1, %8 ], [ 1, %10 ]
ret i32 %13
}