#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ _lock;
};
typedef TYPE_1__ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ __lock(int /*<<< orphan*/ *);
int /*<<< orphan*/ __unlock(int /*<<< orphan*/ *);
int fputc(char, TYPE_1__ *);
int __do_fputs(const char *str, FILE *fp, int trailing_newline) {
  int c;
  int bytes = 0;
  __lock(&fp->_lock);
  while (0 != (c = *str++)) {
    c = fputc(c, fp);
    if (c < 0) {
      __unlock(&fp->_lock);
      return EOF;
    }
    bytes++;
  }
  if (trailing_newline && bytes > 0) {
    c = fputc('\n', fp);
    if (c < 0)
      bytes = EOF;
    else
      bytes++;
  }
  __unlock(&fp->_lock);
  return bytes;
}


x86 assembly (clang, -O0):
<__do_fputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <__lock@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%ecx
mov    %ecx,-0x20(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
je     11b6 <__do_fputs+0x86>
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11a8 <__do_fputs+0x78>
mov    -0x18(%rbp),%rdi
call   1030 <__unlock@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1213 <__do_fputs+0xe3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <__do_fputs+0x23>
cmpl   $0x0,-0x1c(%rbp)
je     1204 <__do_fputs+0xd4>
cmpl   $0x0,-0x24(%rbp)
jle    1204 <__do_fputs+0xd4>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11f6 <__do_fputs+0xc6>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    11ff <__do_fputs+0xcf>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1204 <__do_fputs+0xd4>
mov    -0x18(%rbp),%rdi
call   1030 <__unlock@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__do_fputs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1050 <__lock@plt>
mov    0x0(%rbp),%al
xor    %ebx,%ebx
test   %al,%al
je     11b3 <__do_fputs+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
test   %eax,%eax
js     1197 <__do_fputs+0x67>
movzbl 0x1(%rbp,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <__do_fputs+0x30>
test   %r15d,%r15d
je     11b3 <__do_fputs+0x83>
mov    $0xa,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
test   %eax,%eax
js     11aa <__do_fputs+0x7a>
add    $0x1,%ebx
jmp    11b3 <__do_fputs+0x83>
mov    %r14,%rdi
call   1030 <__unlock@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%ebx
jmp    11bb <__do_fputs+0x8b>
mov    0x2e37(%rip),%rax
mov    (%rax),%ebx
mov    %r14,%rdi
call   1030 <__unlock@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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