#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*/ ft_putchar_fd(char const, int);
void ft_putendl_fd(char const *s, int fd) {
  int i;
  if (s) {
    i = 0;
    while (s[i]) {
      ft_putchar_fd(s[i++], fd);
    }
  }
  ft_putchar_fd('\n', fd);
}


x86 assembly (clang, -O0):
<ft_putendl_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     116d <ft_putendl_fd+0x5d>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1168 <ft_putendl_fd+0x58>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0xc(%rbp),%esi
movsbl %al,%edi
call   1030 <ft_putchar_fd@plt>
jmp    1131 <ft_putendl_fd+0x21>
jmp    116d <ft_putendl_fd+0x5d>
mov    -0xc(%rbp),%esi
mov    $0xa,%edi
call   1030 <ft_putchar_fd@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putendl_fd>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
test   %rdi,%rdi
je     1145 <ft_putendl_fd+0x35>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1145 <ft_putendl_fd+0x35>
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %ebp,%esi
call   1030 <ft_putchar_fd@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <ft_putendl_fd+0x20>
mov    $0xa,%edi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <ft_putchar_fd@plt>

LLVM IR (-O0):
define void @ft_putendl_fd(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %26
8: ; preds = %2
store i32 0, i32* %5
br label %9
9: ; preds = %16, %8
%10 = load i8*, i8** %3
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8, i8* %21
%23 = load i32, i32* %4
%24 = call i32 @ft_putchar_fd(i8 signext %22, i32 %23)
br label %9
25: ; preds = %9
br label %26
26: ; preds = %25, %2
%27 = load i32, i32* %4
%28 = call i32 @ft_putchar_fd(i8 signext 10, i32 %27)
ret void
}

LLVM IR (-O2):
define void @ft_putendl_fd(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %4, %7
%8 = phi i64 [ %10, %7 ], [ 0, %4 ]
%9 = phi i8 [ %13, %7 ], [ %5, %4 ]
%10 = add nuw i64 %8, 1
%11 = tail call i32 @ft_putchar_fd(i8 signext %9, i32 %1)
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %4, %2
%16 = tail call i32 @ft_putchar_fd(i8 signext 10, i32 %1)
ret void
}