#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 EOF;
int _write(int, char *, int);
int strlen(char const *);
int puts(const char *s) {
  int length = strlen(s);
  int numbytes = 0;
  int 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    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
call   1040 <_write@plt>
mov    %eax,-0x10(%rbp)
mov    $0x1,%edx
lea    0xea1(%rip),%rsi
mov    %edx,%edi
call   1040 <_write@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1189 <puts+0x69>
movl   $0x0,-0x14(%rbp)
jmp    1195 <puts+0x75>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puts>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <_write@plt>
mov    %eax,%ebx
lea    0xebb(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1040 <_write@plt>
mov    %eax,%ecx
add    %ebx,%ecx
add    $0x1,%ebp
xor    %eax,%eax
cmp    %ebp,%ecx
je     116a <puts+0x4a>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
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 i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
store i32 0, i32* %4
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = call i32 @_write(i32 1, i8* %8, i32 %9)
store i32 %10, i32* %4
%11 = call i32 @_write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%12 = load i32, i32* %4
%13 = add nsw i32 %12, %11
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
%17 = icmp eq i32 %14, %16
br i1 %17, label %18, label %19
18: ; preds = %1
store i32 0, i32* %5
br label %21
19: ; preds = %1
%20 = load i32, i32* @EOF
store i32 %20, i32* %5
br label %21
21: ; preds = %19, %18
%22 = load i32, i32* %5
ret i32 %22
}

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