#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*/ LoadByteRegistre(int, char const);
int /*<<< orphan*/ LoadRegistre(int, unsigned int);
int StoreRegistre(int);
int /*<<< orphan*/ ipc(int, int);
int write(int fd, const char *buff, unsigned length) {
  length = (length > 240) ? 240 : length;
  unsigned size = 5 + (length / 4) + ((length % 4 != 0) ? 1 : 0);
  LoadRegistre(0, 5);
  LoadRegistre(1, size);
  LoadRegistre(2, 3);
  LoadRegistre(3, fd);
  LoadRegistre(4, length);
  for (int i = 0; i < length; i++)
    LoadByteRegistre(20 + i, buff[i]);
  ipc(3, 5);
  return StoreRegistre(2);
}


x86 assembly (clang, -O0):
<write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0xf0,-0x14(%rbp)
jbe    116c <write+0x2c>
mov    $0xf0,%eax
mov    %eax,-0x20(%rbp)
jmp    1172 <write+0x32>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x2,%eax
add    $0x5,%eax
mov    -0x14(%rbp),%esi
and    $0x3,%esi
xor    %ecx,%ecx
mov    $0x1,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
xor    %edi,%edi
mov    $0x5,%esi
call   1030 <LoadRegistre@plt>
mov    -0x18(%rbp),%esi
mov    $0x1,%edi
call   1030 <LoadRegistre@plt>
mov    $0x2,%edi
mov    $0x3,%esi
call   1030 <LoadRegistre@plt>
mov    -0x4(%rbp),%esi
mov    $0x3,%edi
call   1030 <LoadRegistre@plt>
mov    -0x14(%rbp),%esi
mov    $0x4,%edi
call   1030 <LoadRegistre@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1213 <write+0xd3>
mov    -0x1c(%rbp),%edi
add    $0x14,%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1060 <LoadByteRegistre@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e2 <write+0xa2>
mov    $0x3,%edi
mov    $0x5,%esi
call   1050 <ipc@plt>
mov    $0x2,%edi
call   1040 <StoreRegistre@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %edi,%r14d
cmp    $0xf0,%edx
mov    $0xf0,%r15d
cmovb  %edx,%r15d
mov    %r15d,%ebp
shr    $0x2,%ebp
mov    %r15d,%eax
and    $0x3,%eax
cmp    $0x1,%eax
sbb    $0xffffffff,%ebp
add    $0x5,%ebp
xor    %edi,%edi
mov    $0x5,%esi
call   1030 <LoadRegistre@plt>
mov    $0x1,%edi
mov    %ebp,%esi
call   1030 <LoadRegistre@plt>
mov    $0x2,%edi
mov    $0x3,%esi
call   1030 <LoadRegistre@plt>
mov    $0x3,%edi
mov    %r14d,%esi
call   1030 <LoadRegistre@plt>
mov    $0x4,%edi
mov    %r15d,%esi
call   1030 <LoadRegistre@plt>
test   %r15d,%r15d
je     11d6 <write+0x96>
mov    %r15d,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
movsbl (%r12,%rbx,1),%esi
lea    0x14(%rbx),%edi
call   1060 <LoadByteRegistre@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11c0 <write+0x80>
mov    $0x3,%edi
mov    $0x5,%esi
call   1050 <ipc@plt>
mov    $0x2,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <StoreRegistre@plt>

LLVM IR (-O0):
define i32 @write(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = icmp ugt i32 %9, 240
br i1 %10, label %11, label %12
11: ; preds = %3
br label %14
12: ; preds = %3
%13 = load i32, i32* %6
br label %14
14: ; preds = %12, %11
%15 = phi i32 [ 240, %11 ], [ %13, %12 ]
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = udiv i32 %16, 4
%18 = add i32 5, %17
%19 = load i32, i32* %6
%20 = urem i32 %19, 4
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 1, i32 0
%24 = add i32 %18, %23
store i32 %24, i32* %7
%25 = call i32 @LoadRegistre(i32 0, i32 5)
%26 = load i32, i32* %7
%27 = call i32 @LoadRegistre(i32 1, i32 %26)
%28 = call i32 @LoadRegistre(i32 2, i32 3)
%29 = load i32, i32* %4
%30 = call i32 @LoadRegistre(i32 3, i32 %29)
%31 = load i32, i32* %6
%32 = call i32 @LoadRegistre(i32 4, i32 %31)
store i32 0, i32* %8
br label %33
33: ; preds = %46, %14
%34 = load i32, i32* %8
%35 = load i32, i32* %6
%36 = icmp ult i32 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = load i32, i32* %8
%39 = add nsw i32 20, %38
%40 = load i8*, i8** %5
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = call i32 @LoadByteRegistre(i32 %39, i8 signext %44)
br label %46
46: ; preds = %37
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %33
49: ; preds = %33
%50 = call i32 @ipc(i32 3, i32 5)
%51 = call i32 @StoreRegistre(i32 2)
ret i32 %51
}

LLVM IR (-O2):
define i32 @write(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp ult i32 %2, 240
%5 = select i1 %4, i32 %2, i32 240
%6 = lshr i32 %5, 2
%7 = add nuw nsw i32 %6, 5
%8 = and i32 %5, 3
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %7, %10
%12 = tail call i32 @LoadRegistre(i32 0, i32 5)
%13 = tail call i32 @LoadRegistre(i32 1, i32 %11)
%14 = tail call i32 @LoadRegistre(i32 2, i32 3)
%15 = tail call i32 @LoadRegistre(i32 3, i32 %0)
%16 = tail call i32 @LoadRegistre(i32 4, i32 %5)
%17 = icmp eq i32 %5, 0
br i1 %17, label %20, label %18
18: ; preds = %3
%19 = zext i32 %5 to i64
br label %23
20: ; preds = %23, %3
%21 = tail call i32 @ipc(i32 3, i32 5)
%22 = tail call i32 @StoreRegistre(i32 2)
ret i32 %22
23: ; preds = %18, %23
%24 = phi i64 [ 0, %18 ], [ %30, %23 ]
%25 = getelementptr inbounds i8, i8* %1, i64 %24
%26 = load i8, i8* %25
%27 = trunc i64 %24 to i32
%28 = add i32 %27, 20
%29 = tail call i32 @LoadByteRegistre(i32 %28, i8 signext %26)
%30 = add nuw nsw i64 %24, 1
%31 = icmp eq i64 %30, %19
br i1 %31, label %20, label %23
}