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


x86 assembly (clang, -O0):
<ft_putnchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eaf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
jbe    1188 <ft_putnchar+0x78>
mov    $0x1,%edx
lea    -0x1(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%eax
jne    1171 <ft_putnchar+0x61>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    117d <ft_putnchar+0x6d>
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    112e <ft_putnchar+0x1e>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnchar>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %dil,0xf(%rsp)
mov    0x2eb0(%rip),%r15
mov    (%r15),%ebp
test   %rsi,%rsi
je     1173 <ft_putnchar+0x63>
mov    %rsi,%rbx
lea    0xf(%rsp),%r14
mov    0x2ea1(%rip),%r12
jmp    1156 <ft_putnchar+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbx
je     1173 <ft_putnchar+0x63>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    (%r15),%eax
je     1150 <ft_putnchar+0x40>
mov    (%r12),%ebp
jmp    1150 <ft_putnchar+0x40>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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