#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 */
typedef scalar_t__ uint32_t;
typedef int int8_t;

/* Variables and functions */
int EOF;
scalar_t__ _write(int, char *, int);
scalar_t__ strlen(char const *);
int puts(const char *s) {
  uint32_t length = strlen(s);
  uint32_t numbytes = 0;
  int8_t res;
  numbytes = _write(1, (char *)s, length);
  numbytes += _write(1, "\n", 1);
  if (numbytes == (length + 1)) {
    res = 0;
  } else {
    res = EOF;
  }
  return res;
}


x86 assembly (clang, -O0):
<puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
mov    $0x1,%edi
call   1040 <_write@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edx
lea    0xe9b(%rip),%rsi
mov    %edx,%edi
call   1040 <_write@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1195 <puts+0x75>
movl   $0x0,-0x1c(%rbp)
jmp    11a1 <puts+0x81>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puts>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <_write@plt>
mov    %rax,%r14
lea    0xeb8(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1040 <_write@plt>
mov    %rax,%rcx
add    %r14,%rcx
add    $0x1,%rbx
xor    %eax,%eax
cmp    %rbx,%rcx
je     1171 <puts+0x51>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@EOF = global i32 0
define i32 @puts(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %3
store i64 0, i64* %4
%8 = load i8*, i8** %2
%9 = load i64, i64* %3
%10 = trunc i64 %9 to i32
%11 = call i64 @_write(i32 1, i8* %8, i32 %10)
store i64 %11, i64* %4
%12 = call i64 @_write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%13 = load i64, i64* %4
%14 = add nsw i64 %13, %12
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = load i64, i64* %3
%17 = add nsw i64 %16, 1
%18 = icmp eq i64 %15, %17
br i1 %18, label %19, label %20
19: ; preds = %1
store i32 0, i32* %5
br label %22
20: ; preds = %1
%21 = load i32, i32* @EOF
store i32 %21, i32* %5
br label %22
22: ; preds = %20, %19
%23 = load i32, i32* %5
ret i32 %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@EOF = global i32 0
define i32 @puts(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = tail call i64 @_write(i32 1, i8* %0, i32 %3)
%5 = tail call i64 @_write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%6 = add nsw i64 %5, %4
%7 = add nsw i64 %2, 1
%8 = icmp eq i64 %6, %7
%9 = load i32, i32* @EOF
%10 = select i1 %8, i32 0, i32 %9
ret i32 %10
}