#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*/ isspace(char const);
void strncpy_trim_space(char *dst, const char *src, int size) {
  char mask = 0x0;
  src += size - 1;
  dst += size - 1;
  *(dst + 1) = 0;
  while (size--) {
    if (!isspace(*src)) {
      mask = 0xff;
    }
    *(dst--) = *(src--) & mask;
  }
}


x86 assembly (clang, -O0):
<strncpy_trim_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11b4 <strncpy_trim_space+0xa4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%eax
jne    1184 <strncpy_trim_space+0x74>
movb   $0xff,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
movsbl -0x15(%rbp),%ecx
and    %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1157 <strncpy_trim_space+0x47>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncpy_trim_space>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
movslq %edx,%r14
movb   $0x0,(%rdi,%r14,1)
test   %r14d,%r14d
je     1167 <strncpy_trim_space+0x57>
mov    %rsi,%r12
lea    -0x1(%r14),%rax
lea    (%rdi,%r14,1),%r15
add    $0xffffffffffffffff,%r15
add    %rax,%r12
neg    %r14d
xor    %ebx,%ebx
xor    %r13d,%r13d
movsbl (%r12,%rbx,1),%edi
call   1030 <isspace@plt>
cmp    $0x1,%eax
sbb    %eax,%eax
or     %al,%r13b
movzbl (%r12,%rbx,1),%eax
and    %r13b,%al
mov    %al,(%r15,%rbx,1)
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r14d
jne    1140 <strncpy_trim_space+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @strncpy_trim_space(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = getelementptr inbounds i8, i8* %6, i64 1
store i8 0, i8* %7
%8 = icmp eq i32 %2, 0
br i1 %8, label %26, label %9
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %1, i64 %5
br label %11
11: ; preds = %9, %11
%12 = phi i8 [ %20, %11 ], [ 0, %9 ]
%13 = phi i32 [ %16, %11 ], [ %2, %9 ]
%14 = phi i8* [ %21, %11 ], [ %10, %9 ]
%15 = phi i8* [ %24, %11 ], [ %6, %9 ]
%16 = add nsw i32 %13, -1
%17 = load i8, i8* %14
%18 = tail call i32 @isspace(i8 signext %17)
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8 -1, i8 %12
%21 = getelementptr inbounds i8, i8* %14, i64 -1
%22 = load i8, i8* %14
%23 = and i8 %20, %22
%24 = getelementptr inbounds i8, i8* %15, i64 -1
store i8 %23, i8* %15
%25 = icmp eq i32 %16, 0
br i1 %25, label %26, label %11
26: ; preds = %11, %3
ret void
}