#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 */
typedef int /*<<< orphan*/ wint_t;
typedef int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int /*<<< orphan*/ WEOF;
int /*<<< orphan*/ ft_bzero(char *, int);
int ft_wctomb(char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
wint_t ft_putwchar_fd(wchar_t wc, int fd) {
  char bytes[4];
  int n_bytes;
  ft_bzero(bytes, 4);
  if ((n_bytes = ft_wctomb(bytes, wc)) == -1)
    return (WEOF);
  else
    write(fd, bytes, n_bytes);
  return (wc);
}


x86 assembly (clang, -O0):
<ft_putwchar_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1040 <ft_bzero@plt>
lea    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <ft_wctomb@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1175 <ft_putwchar_fd+0x45>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    118a <ft_putwchar_fd+0x5a>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putwchar_fd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x4,%esi
call   1040 <ft_bzero@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1050 <ft_wctomb@plt>
cmp    $0xffffffff,%eax
je     116f <ft_putwchar_fd+0x3f>
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1178 <ft_putwchar_fd+0x48>
mov    0x2e6a(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@WEOF = global i32 0
define i32 @ft_putwchar_fd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i8]
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%9 = call i32 @ft_bzero(i8* %8, i32 4)
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* %4
%12 = call i32 @ft_wctomb(i8* %10, i32 %11)
store i32 %12, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* @WEOF
store i32 %15, i32* %3
br label %23
16: ; preds = %2
%17 = load i32, i32* %5
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* %7
%20 = call i32 @write(i32 %17, i8* %18, i32 %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %4
store i32 %22, i32* %3
br label %23
23: ; preds = %21, %14
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@WEOF = global i32 0
define i32 @ft_putwchar_fd(i32 %0, i32 %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = call i32 @ft_bzero(i8* %4, i32 4)
%6 = call i32 @ft_wctomb(i8* %4, i32 %0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i32, i32* @WEOF
br label %12
10: ; preds = %2
%11 = call i32 @write(i32 %1, i8* %4, i32 %6)
br label %12
12: ; preds = %10, %8
%13 = phi i32 [ %9, %8 ], [ %0, %10 ]
ret i32 %13
}