#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;
  i = 0;
  if (s) {
    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)
movl   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1179 <ft_putendl_fd+0x69>
jmp    1136 <ft_putendl_fd+0x26>
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
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %26
8: ; preds = %2
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 %19
16: ; preds = %9
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %9
19: ; preds = %9
%20 = load i32, i32* %4
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = call i32 @write(i32 %20, i8* %21, i32 %22)
%24 = load i32, i32* %4
%25 = call i32 @write(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %26
26: ; preds = %19, %2
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 = %10, %2
ret void
}