#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 /*<<< orphan*/ bwputc(char);
void bwputw(int n, char fc, char *bf) {
  char ch;
  char *p = bf;
  while (*p++ && n > 0)
    n--;
  while (n-- > 0)
    bwputc(fc);
  while ((ch = *bf++))
    bwputc(ch);
}


x86 assembly (clang, -O0):
<bwputw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     1157 <bwputw+0x47>
cmpl   $0x0,-0x4(%rbp)
setg   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1167 <bwputw+0x57>
jmp    1175 <bwputw+0x65>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    112d <bwputw+0x1d>
jmp    117a <bwputw+0x6a>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
jle    119c <bwputw+0x8c>
movsbl -0x5(%rbp),%edi
call   1030 <bwputc@plt>
jmp    117a <bwputw+0x6a>
jmp    11a1 <bwputw+0x91>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
cmp    $0x0,%al
je     11cb <bwputw+0xbb>
movsbl -0x11(%rbp),%edi
call   1030 <bwputc@plt>
jmp    11a1 <bwputw+0x91>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bwputw>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    (%rdx),%al
test   %al,%al
je     1145 <bwputw+0x35>
test   %edi,%edi
jle    1145 <bwputw+0x35>
lea    0x1(%rbx),%rcx
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x1(%rdi),%ebp
cmpb   $0x0,(%rcx)
je     1147 <bwputw+0x37>
add    $0x1,%rcx
cmp    $0x1,%edi
mov    %ebp,%edi
ja     1130 <bwputw+0x20>
jmp    1147 <bwputw+0x37>
mov    %edi,%ebp
test   %ebp,%ebp
jle    1172 <bwputw+0x62>
add    $0x1,%ebp
movsbl %sil,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
call   1030 <bwputc@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1160 <bwputw+0x50>
mov    (%rbx),%al
test   %al,%al
je     1193 <bwputw+0x83>
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <bwputc@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <bwputw+0x70>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @bwputw(i32 %0, i8 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
store i32 %0, i32* %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
store i8* %9, i8** %8
br label %10
10: ; preds = %21, %3
%11 = load i8*, i8** %8
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %8
%13 = load i8, i8* %11
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br label %19
19: ; preds = %16, %10
%20 = phi i1 [ false, %10 ], [ %18, %16 ]
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = load i32, i32* %4
%23 = add nsw i32 %22, -1
store i32 %23, i32* %4
br label %10
24: ; preds = %19
br label %25
25: ; preds = %29, %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
%28 = icmp sgt i32 %26, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i8, i8* %5
%31 = call i32 @bwputc(i8 signext %30)
br label %25
32: ; preds = %25
br label %33
33: ; preds = %38, %32
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %6
%36 = load i8, i8* %34
store i8 %36, i8* %7
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i8, i8* %7
%40 = call i32 @bwputc(i8 signext %39)
br label %33
41: ; preds = %33
ret void
}

LLVM IR (-O2):
define void @bwputw(i32 %0, i8 signext %1, i8* nocapture %2) {
%4 = load i8, i8* %2
%5 = icmp ne i8 %4, 0
%6 = icmp sgt i32 %0, 0
%7 = and i1 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %11, %3
%9 = phi i32 [ %0, %3 ], [ %15, %11 ]
%10 = icmp sgt i32 %9, 0
br i1 %10, label %25, label %22
11: ; preds = %3, %11
%12 = phi i8* [ %14, %11 ], [ %2, %3 ]
%13 = phi i32 [ %15, %11 ], [ %0, %3 ]
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = add nsw i32 %13, -1
%16 = load i8, i8* %14
%17 = icmp ne i8 %16, 0
%18 = icmp ugt i32 %13, 1
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %11, label %8
20: ; preds = %25
%21 = load i8, i8* %2
br label %22
22: ; preds = %20, %8
%23 = phi i8 [ %21, %20 ], [ %4, %8 ]
%24 = icmp eq i8 %23, 0
br i1 %24, label %37, label %30
25: ; preds = %8, %25
%26 = phi i32 [ %27, %25 ], [ %9, %8 ]
%27 = add nsw i32 %26, -1
%28 = tail call i32 @bwputc(i8 signext %1)
%29 = icmp ugt i32 %26, 1
br i1 %29, label %25, label %20
30: ; preds = %22, %30
%31 = phi i8 [ %35, %30 ], [ %23, %22 ]
%32 = phi i8* [ %33, %30 ], [ %2, %22 ]
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = tail call i32 @bwputc(i8 signext %31)
%35 = load i8, i8* %33
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %30
37: ; preds = %30, %22
ret void
}