#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*/ EBADF;
#define STDERR_FILENO 129
#define STDOUT_FILENO 128
int /*<<< orphan*/ USART_write(char *, int);
int /*<<< orphan*/ errno;
int _write(int file, char *ptr, int len) {
  switch (file) {
  case STDOUT_FILENO:
    USART_write(ptr, len);
    break;
  case STDERR_FILENO:
    USART_write(ptr, len);
    break;
  default:
    errno = EBADF;
    return -1;
  }
  return len;
}


x86 assembly (clang, -O0):
<_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x80,%eax
je     114b <_write+0x3b>
jmp    1138 <_write+0x28>
mov    -0x18(%rbp),%eax
sub    $0x81,%eax
je     115c <_write+0x4c>
jmp    116d <_write+0x5d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <USART_write@plt>
jmp    118b <_write+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <USART_write@plt>
jmp    118b <_write+0x7b>
mov    0x2e64(%rip),%rax
mov    (%rax),%ecx
mov    0x2e63(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <_write+0x81>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_write>:
push   %rbx
mov    %edx,%ebx
cmp    $0x81,%edi
je     1123 <_write+0x13>
cmp    $0x80,%edi
jne    112f <_write+0x1f>
mov    %rsi,%rdi
mov    %ebx,%esi
call   1030 <USART_write@plt>
jmp    1146 <_write+0x36>
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    0x2ea1(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EBADF = global i32 0
@errno = global i32 0
define i32 @_write(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
switch i32 %8, label %17 [
i32 128, label %9
i32 129, label %13
]
9: ; preds = %3
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i32 @USART_write(i8* %10, i32 %11)
br label %19
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = call i32 @USART_write(i8* %14, i32 %15)
br label %19
17: ; preds = %3
%18 = load i32, i32* @EBADF
store i32 %18, i32* @errno
store i32 -1, i32* %4
br label %21
19: ; preds = %13, %9
%20 = load i32, i32* %7
store i32 %20, i32* %4
br label %21
21: ; preds = %19, %17
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
@EBADF = global i32 0
@errno = global i32 0
define i32 @_write(i32 %0, i8* %1, i32 %2) {
switch i32 %0, label %8 [
i32 128, label %4
i32 129, label %6
]
4: ; preds = %3
%5 = tail call i32 @USART_write(i8* %1, i32 %2)
br label %10
6: ; preds = %3
%7 = tail call i32 @USART_write(i8* %1, i32 %2)
br label %10
8: ; preds = %3
%9 = load i32, i32* @EBADF
store i32 %9, i32* @errno
br label %10
10: ; preds = %4, %6, %8
%11 = phi i32 [ -1, %8 ], [ %2, %6 ], [ %2, %4 ]
ret i32 %11
}