#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
scalar_t__ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
size_t strlen(char const *);
int fputs(const char *s, FILE *stream) {
  size_t len = strlen(s);
  while (len) {
    if (fputc(*s++, stream) == EOF)
      return EOF;
    len--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1196 <fputs+0x76>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1040 <fputc@plt>
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
jne    1185 <fputs+0x65>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    119d <fputs+0x7d>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    113d <fputs+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputs>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %rax,%rax
je     116c <fputs+0x4c>
mov    %rax,%r12
xor    %ebx,%ebx
mov    0x2ea3(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r15,%rbx,1),%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
cmp    0x0(%r13),%rax
je     116e <fputs+0x4e>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <fputs+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@EOF = global i64 0
define i32 @fputs(i8* nocapture %0, i32* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %2, %15
%6 = phi i64 [ %17, %15 ], [ %3, %2 ]
%7 = phi i8* [ %16, %15 ], [ %0, %2 ]
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = tail call i64 @fputc(i32 %9, i32* %1)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = trunc i64 %10 to i32
br label %19
15: ; preds = %5
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = add i64 %6, -1
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %5
19: ; preds = %15, %2, %13
%20 = phi i32 [ %14, %13 ], [ 0, %2 ], [ 0, %15 ]
ret i32 %20
}