#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 */
struct testlog {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ tlog_putc(struct testlog *, char);
int /*<<< orphan*/ tlog_putstr(struct testlog *, char const *);
void tlog_putw(struct testlog *log, int n, char fc, const char *bf) {
  const char *p = bf;
  while (*p++ && n > 0)
    n--;
  while (n-- > 0)
    tlog_putc(log, fc);
  tlog_putstr(log, bf);
}


x86 assembly (clang, -O0):
<tlog_putw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%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     116a <tlog_putw+0x4a>
cmpl   $0x0,-0xc(%rbp)
setg   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117a <tlog_putw+0x5a>
jmp    1188 <tlog_putw+0x68>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1140 <tlog_putw+0x20>
jmp    118d <tlog_putw+0x6d>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    11b3 <tlog_putw+0x93>
mov    -0x8(%rbp),%rdi
movsbl -0xd(%rbp),%esi
call   1040 <tlog_putc@plt>
jmp    118d <tlog_putw+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <tlog_putstr@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tlog_putw>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdi,%r15
cmpb   $0x0,(%rcx)
je     1155 <tlog_putw+0x35>
test   %esi,%esi
jle    1155 <tlog_putw+0x35>
lea    0x1(%r14),%rax
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rsi),%ebx
cmpb   $0x0,(%rax)
je     1157 <tlog_putw+0x37>
add    $0x1,%rax
cmp    $0x1,%esi
mov    %ebx,%esi
ja     1140 <tlog_putw+0x20>
jmp    1157 <tlog_putw+0x37>
mov    %esi,%ebx
test   %ebx,%ebx
jle    1182 <tlog_putw+0x62>
add    $0x1,%ebx
movsbl %dl,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <tlog_putc@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1170 <tlog_putw+0x50>
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <tlog_putstr@plt>

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

LLVM IR (-O2):
%struct.testlog = type { i32 }
define void @tlog_putw(%struct.testlog* %0, i32 %1, i8 signext %2, i8* %3) {
%5 = load i8, i8* %3
%6 = icmp ne i8 %5, 0
%7 = icmp sgt i32 %1, 0
%8 = and i1 %6, %7
br i1 %8, label %12, label %9
9: ; preds = %12, %4
%10 = phi i32 [ %1, %4 ], [ %16, %12 ]
%11 = icmp sgt i32 %10, 0
br i1 %11, label %21, label %26
12: ; preds = %4, %12
%13 = phi i8* [ %15, %12 ], [ %3, %4 ]
%14 = phi i32 [ %16, %12 ], [ %1, %4 ]
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = add nsw i32 %14, -1
%17 = load i8, i8* %15
%18 = icmp ne i8 %17, 0
%19 = icmp ugt i32 %14, 1
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %12, label %9
21: ; preds = %9, %21
%22 = phi i32 [ %23, %21 ], [ %10, %9 ]
%23 = add nsw i32 %22, -1
%24 = tail call i32 @tlog_putc(%struct.testlog* %0, i8 signext %2)
%25 = icmp ugt i32 %22, 1
br i1 %25, label %21, label %26
26: ; preds = %21, %9
%27 = tail call i32 @tlog_putstr(%struct.testlog* %0, i8* %3)
ret void
}