#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*/ kill_trailingn(char *, char, char *);
char *vkill_trailing(char *cstr, int elem_len, int sizeofcstr, char t) {
  int i;
  for (i = 0; i < sizeofcstr / elem_len; i++)
    kill_trailingn(cstr + elem_len * i, t, cstr + elem_len * (i + 1) - 1);
  return cstr;
}


x86 assembly (clang, -O0):
<vkill_trailing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    118b <vkill_trailing+0x7b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x11(%rbp),%al
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%esi
add    $0x1,%esi
imul   %esi,%ecx
movslq %ecx,%rcx
add    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
movsbl %al,%esi
call   1030 <kill_trailingn@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112e <vkill_trailing+0x1e>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vkill_trailing>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%eax
mov    %rdi,%r14
cltd
idiv   %esi
test   %eax,%eax
jle    1158 <vkill_trailing+0x48>
movslq %esi,%r15
mov    %eax,%ebp
lea    -0x1(%r15),%r13
movsbl %cl,%r12d
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%r13,1),%rdx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <kill_trailingn@plt>
add    %r15,%rbx
add    $0xffffffffffffffff,%rbp
jne    1140 <vkill_trailing+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @vkill_trailing(i8* %0, i32 %1, i32 %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8 %3, i8* %8
store i32 0, i32* %9
br label %10
10: ; preds = %33, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = sdiv i32 %12, %13
%15 = icmp slt i32 %11, %14
br i1 %15, label %16, label %36
16: ; preds = %10
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = load i32, i32* %9
%20 = mul nsw i32 %18, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
%23 = load i8, i8* %8
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
%28 = mul nsw i32 %25, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %24, i64 %29
%31 = getelementptr inbounds i8, i8* %30, i64 -1
%32 = call i32 @kill_trailingn(i8* %22, i8 signext %23, i8* %31)
br label %33
33: ; preds = %16
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %10
36: ; preds = %10
%37 = load i8*, i8** %5
ret i8* %37
}

LLVM IR (-O2):
define i8* @vkill_trailing(i8* returned %0, i32 %1, i32 %2, i8 signext %3) {
%5 = sdiv i32 %2, %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = sext i32 %1 to i64
%9 = zext i32 %5 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 -1
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %15, %11 ]
%13 = mul nsw i64 %12, %8
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = add nuw nsw i64 %12, 1
%16 = mul nsw i64 %15, %8
%17 = getelementptr inbounds i8, i8* %10, i64 %16
%18 = tail call i32 @kill_trailingn(i8* %14, i8 signext %3, i8* %17)
%19 = icmp eq i64 %15, %9
br i1 %19, label %20, label %11
20: ; preds = %11, %4
ret i8* %0
}