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


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)
jne    112f <ft_putendl_fd+0x1f>
jmp    1179 <ft_putendl_fd+0x69>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1156 <ft_putendl_fd+0x46>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <ft_putendl_fd+0x26>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    0xe91(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putendl_fd>:
test   %rdi,%rdi
je     1148 <ft_putendl_fd+0x38>
push   %rbx
mov    %esi,%ebx
mov    %rdi,%rsi
xor    %edx,%edx
nopl   (%rax)
cmpb   $0x0,(%rsi,%rdx,1)
lea    0x1(%rdx),%rdx
jne    1120 <ft_putendl_fd+0x10>
add    $0xffffffff,%edx
mov    %ebx,%edi
call   1030 <write@plt>
lea    0xec5(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
pop    %rbx
jmp    1030 <write@plt>
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
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 %9, label %8
8: ; preds = %2
br label %27
9: ; preds = %2
store i32 0, i32* %5
br label %10
10: ; preds = %17, %9
%11 = load i8*, i8** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %10
20: ; preds = %10
%21 = load i32, i32* %4
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = call i32 @write(i32 %21, i8* %22, i32 %23)
%25 = load i32, i32* %4
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %27
27: ; preds = %20, %8
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define void @ft_putendl_fd(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %14, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %9, %4 ], [ 0, %2 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = add nuw i64 %5, 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = trunc i64 %5 to i32
%12 = tail call i32 @write(i32 %1, i8* %0, i32 %11)
%13 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %14
14: ; preds = %2, %10
ret void
}