#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*/ write(int, int *, int);
void ft_putchar_fd(int c, int fd) {
  int result;
  if (c < 0x80)
    write(fd, &c, 1);
  else if (c < 0x800) {
    result = ((c >> 6) | 0xC0) + (((c & 0x3F) | 0x80) << 8);
    write(fd, &result, 2);
  } else if (c < 0x10000) {
    result = ((c >> 12) | 0xE0) + ((((c >> 6) & 0x3F) | 0x80) << 8);
    result += ((c & 0x3F) | 0x80) << 16;
    write(fd, &result, 3);
  } else if (c < 0x110000) {
    result = ((c >> 18) | 0xF0) + ((((c >> 12) & 0x3F) | 0x80) << 8);
    result += (((c >> 6) & 0x3F) | 0x80) << 16;
    result += ((c & 0x3F) | 0x80) << 24;
    write(fd, &result, 4);
  }
  return;
}


x86 assembly (clang, -O0):
<ft_putchar_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x80,-0x4(%rbp)
jge    1141 <ft_putchar_fd+0x31>
mov    -0x8(%rbp),%edi
lea    -0x4(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1256 <ft_putchar_fd+0x146>
cmpl   $0x800,-0x4(%rbp)
jge    1183 <ft_putchar_fd+0x73>
mov    -0x4(%rbp),%eax
sar    $0x6,%eax
or     $0xc0,%eax
mov    -0x4(%rbp),%ecx
and    $0x3f,%ecx
or     $0x80,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
jmp    1251 <ft_putchar_fd+0x141>
cmpl   $0x10000,-0x4(%rbp)
jge    11dc <ft_putchar_fd+0xcc>
mov    -0x4(%rbp),%eax
sar    $0xc,%eax
or     $0xe0,%eax
mov    -0x4(%rbp),%ecx
sar    $0x6,%ecx
and    $0x3f,%ecx
or     $0x80,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
shl    $0x10,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
jmp    124c <ft_putchar_fd+0x13c>
cmpl   $0x110000,-0x4(%rbp)
jge    1247 <ft_putchar_fd+0x137>
mov    -0x4(%rbp),%eax
sar    $0x12,%eax
or     $0xf0,%eax
mov    -0x4(%rbp),%ecx
sar    $0xc,%ecx
and    $0x3f,%ecx
or     $0x80,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x6,%eax
and    $0x3f,%eax
or     $0x80,%eax
shl    $0x10,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3f,%eax
or     $0x80,%eax
shl    $0x18,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    124c <ft_putchar_fd+0x13c>
jmp    1251 <ft_putchar_fd+0x141>
jmp    1256 <ft_putchar_fd+0x146>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putchar_fd>:
push   %rax
mov    %edi,0x4(%rsp)
cmp    $0x7f,%edi
jg     112e <ft_putchar_fd+0x1e>
lea    0x4(%rsp),%rax
mov    %esi,%edi
mov    %rax,%rsi
mov    $0x1,%edx
jmp    11e6 <ft_putchar_fd+0xd6>
cmp    $0x7ff,%edi
ja     1162 <ft_putchar_fd+0x52>
mov    %edi,%eax
shr    $0x6,%eax
or     $0xc0,%eax
and    $0x3f,%edi
shl    $0x8,%edi
add    %edi,%eax
add    $0x8000,%eax
mov    %eax,(%rsp)
mov    %rsp,%rax
mov    %esi,%edi
mov    %rax,%rsi
mov    $0x2,%edx
jmp    11e6 <ft_putchar_fd+0xd6>
cmp    $0xffff,%edi
ja     119e <ft_putchar_fd+0x8e>
mov    %edi,%eax
shr    $0xc,%eax
or     $0xe0,%eax
mov    %edi,%ecx
and    $0xfc0,%ecx
and    $0x3f,%edi
shl    $0x10,%edi
lea    (%rdi,%rcx,4),%ecx
add    %ecx,%eax
add    $0x808000,%eax
mov    %eax,(%rsp)
mov    %rsp,%rax
mov    %esi,%edi
mov    %rax,%rsi
mov    $0x3,%edx
jmp    11e6 <ft_putchar_fd+0xd6>
cmp    $0x10ffff,%edi
ja     11eb <ft_putchar_fd+0xdb>
mov    %edi,%eax
shr    $0x12,%eax
or     $0xf0,%eax
mov    %edi,%ecx
shr    $0x4,%ecx
and    $0x3f00,%ecx
add    %eax,%ecx
mov    %edi,%eax
shl    $0xa,%eax
and    $0x3f0000,%eax
or     %ecx,%eax
and    $0x3f,%edi
shl    $0x18,%edi
add    %edi,%eax
add    $0x80808000,%eax
mov    %eax,(%rsp)
mov    %rsp,%rax
mov    %esi,%edi
mov    %rax,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @ft_putchar_fd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 128
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %4
%10 = call i32 @write(i32 %9, i32* %3, i32 1)
br label %77
11: ; preds = %2
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 2048
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i32, i32* %3
%16 = ashr i32 %15, 6
%17 = or i32 %16, 192
%18 = load i32, i32* %3
%19 = and i32 %18, 63
%20 = or i32 %19, 128
%21 = shl i32 %20, 8
%22 = add nsw i32 %17, %21
store i32 %22, i32* %5
%23 = load i32, i32* %4
%24 = call i32 @write(i32 %23, i32* %5, i32 2)
br label %76
25: ; preds = %11
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 65536
br i1 %27, label %28, label %46
28: ; preds = %25
%29 = load i32, i32* %3
%30 = ashr i32 %29, 12
%31 = or i32 %30, 224
%32 = load i32, i32* %3
%33 = ashr i32 %32, 6
%34 = and i32 %33, 63
%35 = or i32 %34, 128
%36 = shl i32 %35, 8
%37 = add nsw i32 %31, %36
store i32 %37, i32* %5
%38 = load i32, i32* %3
%39 = and i32 %38, 63
%40 = or i32 %39, 128
%41 = shl i32 %40, 16
%42 = load i32, i32* %5
%43 = add nsw i32 %42, %41
store i32 %43, i32* %5
%44 = load i32, i32* %4
%45 = call i32 @write(i32 %44, i32* %5, i32 3)
br label %75
46: ; preds = %25
%47 = load i32, i32* %3
%48 = icmp slt i32 %47, 1114112
br i1 %48, label %49, label %74
49: ; preds = %46
%50 = load i32, i32* %3
%51 = ashr i32 %50, 18
%52 = or i32 %51, 240
%53 = load i32, i32* %3
%54 = ashr i32 %53, 12
%55 = and i32 %54, 63
%56 = or i32 %55, 128
%57 = shl i32 %56, 8
%58 = add nsw i32 %52, %57
store i32 %58, i32* %5
%59 = load i32, i32* %3
%60 = ashr i32 %59, 6
%61 = and i32 %60, 63
%62 = or i32 %61, 128
%63 = shl i32 %62, 16
%64 = load i32, i32* %5
%65 = add nsw i32 %64, %63
store i32 %65, i32* %5
%66 = load i32, i32* %3
%67 = and i32 %66, 63
%68 = or i32 %67, 128
%69 = shl i32 %68, 24
%70 = load i32, i32* %5
%71 = add nsw i32 %70, %69
store i32 %71, i32* %5
%72 = load i32, i32* %4
%73 = call i32 @write(i32 %72, i32* %5, i32 4)
br label %74
74: ; preds = %49, %46
br label %75
75: ; preds = %74, %28
br label %76
76: ; preds = %75, %14
br label %77
77: ; preds = %76, %8
ret void
}

LLVM IR (-O2):
define void @ft_putchar_fd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = bitcast i32* %4 to i8*
%6 = icmp slt i32 %0, 128
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @write(i32 %1, i32* %3, i32 1)
br label %50
9: ; preds = %2
%10 = icmp ult i32 %0, 2048
br i1 %10, label %11, label %19
11: ; preds = %9
%12 = lshr i32 %0, 6
%13 = or i32 %12, 192
%14 = shl nuw nsw i32 %0, 8
%15 = and i32 %14, 16128
%16 = or i32 %15, 32768
%17 = add nuw nsw i32 %16, %13
store i32 %17, i32* %4
%18 = call i32 @write(i32 %1, i32* %4, i32 2)
br label %50
19: ; preds = %9
%20 = icmp ult i32 %0, 65536
br i1 %20, label %21, label %32
21: ; preds = %19
%22 = lshr i32 %0, 12
%23 = or i32 %22, 224
%24 = shl nuw nsw i32 %0, 2
%25 = and i32 %24, 16128
%26 = shl nuw i32 %0, 16
%27 = and i32 %26, 4128768
%28 = or i32 %27, %25
%29 = or i32 %28, 8421376
%30 = add nuw nsw i32 %29, %23
store i32 %30, i32* %4
%31 = call i32 @write(i32 %1, i32* %4, i32 3)
br label %50
32: ; preds = %19
%33 = icmp ult i32 %0, 1114112
br i1 %33, label %34, label %50
34: ; preds = %32
%35 = lshr i32 %0, 18
%36 = or i32 %35, 240
%37 = lshr i32 %0, 4
%38 = and i32 %37, 16128
%39 = or i32 %38, 32768
%40 = add nuw nsw i32 %39, %36
%41 = shl nuw nsw i32 %0, 10
%42 = and i32 %41, 4128768
%43 = or i32 %42, 8388608
%44 = or i32 %40, %43
%45 = shl i32 %0, 24
%46 = and i32 %45, 1056964608
%47 = or i32 %46, -2147483648
%48 = or i32 %44, %47
store i32 %48, i32* %4
%49 = call i32 @write(i32 %1, i32* %4, i32 4)
br label %50
50: ; preds = %11, %32, %34, %21, %7
ret void
}