#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*/ memcpy(char *, char const *, int);
int strlen(char const *);
int save(char const *recp, int reclen, char *buf, int bufsize,
         char const *udata, int uleng) {
  (void)udata, (void)uleng;
  int keylen = strlen(recp) + 1;
  memcpy(buf, recp, reclen < bufsize ? reclen : bufsize);
  if (keylen <= bufsize)
    buf[keylen - 1] = '\t';
  buf[bufsize - 1] = 0;
  return reclen;
}


x86 assembly (clang, -O0):
<save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1174 <save+0x54>
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    117a <save+0x5a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11a7 <save+0x87>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x9,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r15d
cmp    %ebp,%r12d
mov    %ebp,%edx
cmovl  %r12d,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <memcpy@plt>
cmp    %ebp,%r15d
jge    115c <save+0x3c>
movslq %r15d,%rax
movb   $0x9,(%r14,%rax,1)
movslq %ebp,%rax
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @save(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%14 = load i8*, i8** %11
%15 = load i32, i32* %12
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, 1
store i32 %18, i32* %13
%19 = load i8*, i8** %9
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = load i32, i32* %10
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %6
%25 = load i32, i32* %8
br label %28
26: ; preds = %6
%27 = load i32, i32* %10
br label %28
28: ; preds = %26, %24
%29 = phi i32 [ %25, %24 ], [ %27, %26 ]
%30 = call i32 @memcpy(i8* %19, i8* %20, i32 %29)
%31 = load i32, i32* %13
%32 = load i32, i32* %10
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = load i8*, i8** %9
%36 = load i32, i32* %13
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 9, i8* %39
br label %40
40: ; preds = %34, %28
%41 = load i8*, i8** %9
%42 = load i32, i32* %10
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* %8
ret i32 %46
}

LLVM IR (-O2):
define i32 @save(i8* %0, i32 returned %1, i8* %2, i32 %3, i8* nocapture readnone %4, i32 %5) {
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp slt i32 %1, %3
%9 = select i1 %8, i32 %1, i32 %3
%10 = tail call i32 @memcpy(i8* %2, i8* %0, i32 %9)
%11 = icmp slt i32 %7, %3
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds i8, i8* %2, i64 %13
store i8 9, i8* %14
br label %15
15: ; preds = %12, %6
%16 = add nsw i32 %3, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %2, i64 %17
store i8 0, i8* %18
ret i32 %1
}