#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*/ errno;
int _write(int file, char *ptr, int len) {
  int n;
  switch (file) {
  case STDOUT_FILENO:
    for (n = 0; n < len; n++) {
    }
    break;
  case STDERR_FILENO:
    for (n = 0; n < len; n++) {
    }
    break;
  default:
    errno = EBADF;
    return -1;
  }
  return len;
}


x86 assembly (clang, -O0):
<_write>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80,%eax
je     1137 <_write+0x37>
jmp    1124 <_write+0x24>
mov    -0x1c(%rbp),%eax
sub    $0x81,%eax
je     1162 <_write+0x62>
jmp    118d <_write+0x8d>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    115d <_write+0x5d>
jmp    114f <_write+0x4f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <_write+0x3e>
jmp    11ab <_write+0xab>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1188 <_write+0x88>
jmp    117a <_write+0x7a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1169 <_write+0x69>
jmp    11ab <_write+0xab>
mov    0x2e44(%rip),%rax
mov    (%rax),%ecx
mov    0x2e43(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <_write+0xb1>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_write>:
mov    %edx,%eax
and    $0xfffffffe,%edi
cmp    $0x80,%edi
je     1124 <_write+0x24>
mov    0x2ec4(%rip),%rax
mov    (%rax),%eax
mov    0x2ec3(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
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
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
switch i32 %9, label %30 [
i32 128, label %10
i32 129, label %20
]
10: ; preds = %3
store i32 0, i32* %8
br label %11
11: ; preds = %16, %10
%12 = load i32, i32* %8
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
br label %16
16: ; preds = %15
%17 = load i32, i32* %8
%18 = add nsw i32 %17, 1
store i32 %18, i32* %8
br label %11
19: ; preds = %11
br label %32
20: ; preds = %3
store i32 0, i32* %8
br label %21
21: ; preds = %26, %20
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %29
25: ; preds = %21
br label %26
26: ; preds = %25
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %21
29: ; preds = %21
br label %32
30: ; preds = %3
%31 = load i32, i32* @EBADF
store i32 %31, i32* @errno
store i32 -1, i32* %4
br label %34
32: ; preds = %29, %19
%33 = load i32, i32* %7
store i32 %33, i32* %4
br label %34
34: ; preds = %32, %30
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@EBADF = global i32 0
@errno = global i32 0
define i32 @_write(i32 %0, i8* nocapture readnone %1, i32 %2) {
%4 = and i32 %0, -2
%5 = icmp eq i32 %4, 128
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = load i32, i32* @EBADF
store i32 %7, i32* @errno
br label %8
8: ; preds = %3, %6
%9 = phi i32 [ -1, %6 ], [ %2, %3 ]
ret i32 %9
}