#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 */
typedef size_t int32_t;

/* Variables and functions */
size_t EXIT_FAILURE;
size_t EXIT_SUCCESS;
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int32_t trim(const char *s1, char *s2) {
  int32_t i = 0;
  if (!s1) {
    return (EXIT_FAILURE);
  }
  for (i = 132 - 1; i >= 0; --i) {
    if (s1[i] != 32) {
      break;
    } else {
      s2[i] = '\0';
    }
  }
  strncpy(s2, s1, i + 1);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <trim+0x36>
mov    0x2ea6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <trim+0xa8>
movq   $0x83,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jb     1195 <trim+0x85>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1173 <trim+0x63>
jmp    1195 <trim+0x85>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1184 <trim+0x74>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    114e <trim+0x3e>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %rax
test   %rdi,%rdi
je     1157 <trim+0x47>
mov    %rdi,%rax
mov    $0x84,%edx
cmpb   $0x20,0x83(%rdi)
jne    1143 <trim+0x33>
mov    $0x84,%ecx
nopl   0x0(%rax)
movb   $0x0,-0x1(%rsi,%rcx,1)
lea    -0x1(%rcx),%rdx
cmpb   $0x20,-0x2(%rax,%rcx,1)
mov    %rdx,%rcx
je     1130 <trim+0x20>
mov    %rsi,%rdi
mov    %rax,%rsi
call   1030 <strncpy@plt>
mov    0x2e83(%rip),%rax
jmp    115e <trim+0x4e>
mov    0x2e82(%rip),%rax
mov    (%rax),%rax
pop    %rcx
ret

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

LLVM IR (-O2):
@EXIT_FAILURE = global i64 0
@EXIT_SUCCESS = global i64 0
define i64 @trim(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %18, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 131
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 32
br i1 %7, label %8, label %15
8: ; preds = %4, %8
%9 = phi i64 [ %11, %8 ], [ 131, %4 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 0, i8* %10
%11 = add i64 %9, -1
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 32
br i1 %14, label %8, label %15
15: ; preds = %8, %4
%16 = phi i64 [ 132, %4 ], [ %9, %8 ]
%17 = tail call i32 @strncpy(i8* %1, i8* %0, i64 %16)
br label %18
18: ; preds = %2, %15
%19 = phi i64* [ @EXIT_SUCCESS, %15 ], [ @EXIT_FAILURE, %2 ]
%20 = load i64, i64* %19
ret i64 %20
}