#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 termp {
  int dummy;
};

/* Variables and functions */
size_t term_strlen(struct termp *, char *);
int /*<<< orphan*/ term_word(struct termp *, char *);
void tbl_char(struct termp *tp, char c, size_t len) {
  size_t i, sz;
  char cp[2];
  cp[0] = c;
  cp[1] = '\0';
  sz = term_strlen(tp, cp);
  for (i = 0; i < len; i += sz)
    term_word(tp, cp);
}


x86 assembly (clang, -O0):
<tbl_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x2a(%rbp)
movb   $0x0,-0x29(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
call   1040 <term_strlen@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1185 <tbl_char+0x65>
mov    -0x8(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
call   1030 <term_word@plt>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1159 <tbl_char+0x39>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tbl_char>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rdi,%r15
mov    %sil,0xe(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xe(%rsp),%rsi
call   1040 <term_strlen@plt>
test   %r14,%r14
je     1173 <tbl_char+0x53>
mov    %rax,%r13
xor    %ebx,%ebx
lea    0xe(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <term_word@plt>
add    %r13,%rbx
cmp    %r14,%rbx
jb     1160 <tbl_char+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termp = type { i32 }
define void @tbl_char(%struct.termp* %0, i8 signext %1, i64 %2) {
%4 = alloca %struct.termp*
%5 = alloca i8
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca [2 x i8]
store %struct.termp* %0, %struct.termp** %4
store i8 %1, i8* %5
store i64 %2, i64* %6
%10 = load i8, i8* %5
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
store i8 %10, i8* %11
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
store i8 0, i8* %12
%13 = load %struct.termp*, %struct.termp** %4
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%15 = call i64 @term_strlen(%struct.termp* %13, i8* %14)
store i64 %15, i64* %8
store i64 0, i64* %7
br label %16
16: ; preds = %24, %3
%17 = load i64, i64* %7
%18 = load i64, i64* %6
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load %struct.termp*, %struct.termp** %4
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%23 = call i32 @term_word(%struct.termp* %21, i8* %22)
br label %24
24: ; preds = %20
%25 = load i64, i64* %8
%26 = load i64, i64* %7
%27 = add i64 %26, %25
store i64 %27, i64* %7
br label %16
28: ; preds = %16
ret void
}

LLVM IR (-O2):
%struct.termp = type { i32 }
define void @tbl_char(%struct.termp* %0, i8 signext %1, i64 %2) {
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %1, i8* %5
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %6
%7 = call i64 @term_strlen(%struct.termp* %0, i8* %5)
%8 = icmp eq i64 %2, 0
br i1 %8, label %14, label %9
9: ; preds = %3, %9
%10 = phi i64 [ %12, %9 ], [ 0, %3 ]
%11 = call i32 @term_word(%struct.termp* %0, i8* %5)
%12 = add i64 %10, %7
%13 = icmp ult i64 %12, %2
br i1 %13, label %9, label %14
14: ; preds = %9, %3
ret void
}