#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int write(int, char *, int);
int ft_putnchar_fd(char c, size_t n, int fd) {
  int ret;
  ret = EXIT_SUCCESS;
  while (n-- > 0)
    ret = write(fd, &c, 1) == EXIT_SUCCESS ? ret : EXIT_FAILURE;
  return (ret);
}


x86 assembly (clang, -O0):
<ft_putnchar_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
jbe    118c <ft_putnchar_fd+0x7c>
mov    -0x14(%rbp),%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%eax
jne    1175 <ft_putnchar_fd+0x65>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <ft_putnchar_fd+0x71>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1131 <ft_putnchar_fd+0x21>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnchar_fd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %dil,0x7(%rsp)
mov    0x2eb1(%rip),%r12
mov    (%r12),%r14d
test   %rsi,%rsi
je     1171 <ft_putnchar_fd+0x61>
mov    %edx,%ebp
mov    %rsi,%rbx
lea    0x7(%rsp),%r15
mov    0x2e9f(%rip),%r13
jmp    1156 <ft_putnchar_fd+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffffffffffff,%rbx
je     1171 <ft_putnchar_fd+0x61>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    (%r12),%eax
je     1150 <ft_putnchar_fd+0x40>
mov    0x0(%r13),%r14d
jmp    1150 <ft_putnchar_fd+0x40>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @ft_putnchar_fd(i8 signext %0, i64 %1, i32 %2) {
%4 = alloca i8
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i8 %0, i8* %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%8 = load i32, i32* @EXIT_SUCCESS
store i32 %8, i32* %7
br label %9
9: ; preds = %22, %3
%10 = load i64, i64* %5
%11 = add i64 %10, -1
store i64 %11, i64* %5
%12 = icmp ugt i64 %10, 0
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %6
%15 = call i32 @write(i32 %14, i8* %4, i32 1)
%16 = load i32, i32* @EXIT_SUCCESS
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i32, i32* %7
br label %22
20: ; preds = %13
%21 = load i32, i32* @EXIT_FAILURE
br label %22
22: ; preds = %20, %18
%23 = phi i32 [ %19, %18 ], [ %21, %20 ]
store i32 %23, i32* %7
br label %9
24: ; preds = %9
%25 = load i32, i32* %7
ret i32 %25
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @ft_putnchar_fd(i8 signext %0, i64 %1, i32 %2) {
%4 = alloca i8
store i8 %0, i8* %4
%5 = load i32, i32* @EXIT_SUCCESS
%6 = icmp eq i64 %1, 0
br i1 %6, label %17, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %15, %7 ], [ %5, %3 ]
%9 = phi i64 [ %10, %7 ], [ %1, %3 ]
%10 = add i64 %9, -1
%11 = call i32 @write(i32 %2, i8* %4, i32 1)
%12 = load i32, i32* @EXIT_SUCCESS
%13 = icmp eq i32 %11, %12
%14 = load i32, i32* @EXIT_FAILURE
%15 = select i1 %13, i32 %8, i32 %14
%16 = icmp eq i64 %10, 0
br i1 %16, label %17, label %7
17: ; preds = %7, %3
%18 = phi i32 [ %5, %3 ], [ %15, %7 ]
ret i32 %18
}