#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*/ outbyte(int /*<<< orphan*/);
int write(int fd, const char *buf, int len) {
  int _len = len;
  if (fd != 1 && fd != 2)
    return (-1);
  while (_len > 0) {
    outbyte(*buf++);
    _len--;
  }
  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    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1148 <write+0x38>
cmpl   $0x2,-0x8(%rbp)
je     1148 <write+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    1182 <write+0x72>
jmp    114d <write+0x3d>
cmpl   $0x0,-0x18(%rbp)
jle    117c <write+0x6c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <outbyte@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    114d <write+0x3d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write>:
push   %rbp
push   %r14
push   %rbx
add    $0xfffffffd,%edi
mov    $0xffffffff,%eax
cmp    $0xfffffffe,%edi
jb     1147 <write+0x37>
mov    %edx,%r14d
test   %edx,%edx
jle    1144 <write+0x34>
mov    %rsi,%rbx
lea    0x1(%r14),%ebp
nop
movsbl (%rbx),%edi
add    $0x1,%rbx
call   1030 <outbyte@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1130 <write+0x20>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
store i32 %9, i32* %8
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 -1, i32* %4
br label %30
16: ; preds = %12, %3
br label %17
17: ; preds = %20, %16
%18 = load i32, i32* %8
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %6
%23 = load i8, i8* %21
%24 = sext i8 %23 to i32
%25 = call i32 @outbyte(i32 %24)
%26 = load i32, i32* %8
%27 = add nsw i32 %26, -1
store i32 %27, i32* %8
br label %17
28: ; preds = %17
%29 = load i32, i32* %7
store i32 %29, i32* %4
br label %30
30: ; preds = %28, %15
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @write(i32 %0, i8* nocapture %1, i32 %2) {
%4 = add i32 %0, -3
%5 = icmp ult i32 %4, -2
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %17
8: ; preds = %6, %8
%9 = phi i32 [ %15, %8 ], [ %2, %6 ]
%10 = phi i8* [ %11, %8 ], [ %1, %6 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = sext i8 %12 to i32
%14 = tail call i32 @outbyte(i32 %13)
%15 = add nsw i32 %9, -1
%16 = icmp ugt i32 %9, 1
br i1 %16, label %8, label %17
17: ; preds = %8, %6, %3
%18 = phi i32 [ -1, %3 ], [ %2, %6 ], [ %2, %8 ]
ret i32 %18
}