#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int _flags;
};
typedef TYPE_1__ FILE;

/* Variables and functions */
scalar_t__ EOF;
int _IONBF;
scalar_t__ fputc(int /*<<< orphan*/, TYPE_1__ *);
size_t fwrite(char const *, int, size_t, TYPE_1__ *);
size_t strlen(char const *);
int fputs(const char *s, FILE *stream) {
  size_t len;
  len = strlen(s);
  if (stream->_flags & _IONBF) {
    while (len-- && fputc(*s++, stream) != EOF)
      ;
    if (*s != '\0')
      return EOF;
  } else {
    if (fwrite(s, 1, len, stream) != len)
      return EOF;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2e86(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ef <fputs+0xbf>
jmp    116a <fputs+0x3a>
mov    -0x20(%rbp),%rcx
mov    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     11b3 <fputs+0x83>
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    0x2e3e(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11c3 <fputs+0x93>
jmp    11c8 <fputs+0x98>
jmp    116a <fputs+0x3a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ea <fputs+0xba>
mov    0x2e09(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    122d <fputs+0xfd>
jmp    1226 <fputs+0xf6>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
cmp    -0x20(%rbp),%rax
je     1221 <fputs+0xf1>
mov    0x2dd2(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    122d <fputs+0xfd>
jmp    1226 <fputs+0xf6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputs>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
test   %eax,(%r14)
je     1186 <fputs+0x56>
mov    0x2e8d(%rip),%r12
nopl   0x0(%rax,%rax,1)
sub    $0x1,%r15
jb     117b <fputs+0x4b>
movsbl (%rbx),%edi
add    $0x1,%rbx
mov    %r14,%rsi
call   1040 <fputc@plt>
cmp    (%r12),%rax
jne    1160 <fputs+0x30>
cmpb   $0x0,(%rbx)
je     11ae <fputs+0x7e>
mov    (%r12),%eax
jmp    11b0 <fputs+0x80>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <fwrite@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %r15,%rcx
je     11b0 <fputs+0x80>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
jmp    11b0 <fputs+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
@_IONBF = global i32 0
@EOF = global i64 0
define i32 @fputs(i8* %0, %struct.TYPE_5__* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.TYPE_5__*
%6 = alloca i64
store i8* %0, i8** %4
store %struct.TYPE_5__* %1, %struct.TYPE_5__** %5
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @_IONBF
%13 = and i32 %11, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %41
15: ; preds = %2
br label %16
16: ; preds = %31, %15
%17 = load i64, i64* %6
%18 = add i64 %17, -1
store i64 %18, i64* %6
%19 = icmp ne i64 %17, 0
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
%23 = load i8, i8* %21
%24 = sext i8 %23 to i32
%25 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%26 = call i64 @fputc(i32 %24, %struct.TYPE_5__* %25)
%27 = load i64, i64* @EOF
%28 = icmp ne i64 %26, %27
br label %29
29: ; preds = %20, %16
%30 = phi i1 [ false, %16 ], [ %28, %20 ]
br i1 %30, label %31, label %32
31: ; preds = %29
br label %16
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i64, i64* @EOF
%39 = trunc i64 %38 to i32
store i32 %39, i32* %3
br label %53
40: ; preds = %32
br label %52
41: ; preds = %2
%42 = load i8*, i8** %4
%43 = load i64, i64* %6
%44 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%45 = call i64 @fwrite(i8* %42, i32 1, i64 %43, %struct.TYPE_5__* %44)
%46 = load i64, i64* %6
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = load i64, i64* @EOF
%50 = trunc i64 %49 to i32
store i32 %50, i32* %3
br label %53
51: ; preds = %41
br label %52
52: ; preds = %51, %40
store i32 0, i32* %3
br label %53
53: ; preds = %52, %48, %37
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
@_IONBF = global i32 0
@EOF = global i64 0
define i32 @fputs(i8* nocapture %0, %struct.TYPE_5__* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = load i32, i32* @_IONBF
%7 = and i32 %6, %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %28, label %9
9: ; preds = %2, %13
%10 = phi i8* [ %15, %13 ], [ %0, %2 ]
%11 = phi i64 [ %14, %13 ], [ %3, %2 ]
%12 = icmp eq i64 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = add i64 %11, -1
%15 = getelementptr inbounds i8, i8* %10, i64 1
%16 = load i8, i8* %10
%17 = sext i8 %16 to i32
%18 = tail call i64 @fputc(i32 %17, %struct.TYPE_5__* %1)
%19 = load i64, i64* @EOF
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %9
21: ; preds = %9, %13
%22 = phi i8* [ %15, %13 ], [ %10, %9 ]
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %34, label %25
25: ; preds = %21
%26 = load i64, i64* @EOF
%27 = trunc i64 %26 to i32
br label %34
28: ; preds = %2
%29 = tail call i64 @fwrite(i8* %0, i32 1, i64 %3, %struct.TYPE_5__* %1)
%30 = icmp eq i64 %29, %3
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i64, i64* @EOF
%33 = trunc i64 %32 to i32
br label %34
34: ; preds = %21, %28, %31, %25
%35 = phi i32 [ %27, %25 ], [ %33, %31 ], [ 0, %28 ], [ 0, %21 ]
ret i32 %35
}