#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 IMIN(int, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int save(char const *recp, int reclen, char *buf, int bufsize,
         char const *udata __attribute__((unused)),
         int uleng __attribute__((unused))) {
  if (bufsize > 0) {
    int len = IMIN(reclen, bufsize - 1);
    memcpy(buf, recp, len);
    buf[len] = 0;
  }
  return reclen + 1;
}


x86 assembly (clang, -O0):
<save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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)
cmpl   $0x0,-0x1c(%rbp)
jle    1175 <save+0x55>
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
call   1030 <IMIN@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
test   %ecx,%ecx
jle    1156 <save+0x36>
mov    %rdx,%r14
mov    %rdi,%r15
add    $0xffffffff,%ecx
mov    %ebx,%edi
mov    %ecx,%esi
call   1030 <IMIN@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
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 i32, i32* %10
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %6
%17 = load i32, i32* %8
%18 = load i32, i32* %10
%19 = sub nsw i32 %18, 1
%20 = call i32 @IMIN(i32 %17, i32 %19)
store i32 %20, i32* %13
%21 = load i8*, i8** %9
%22 = load i8*, i8** %7
%23 = load i32, i32* %13
%24 = call i32 @memcpy(i8* %21, i8* %22, i32 %23)
%25 = load i8*, i8** %9
%26 = load i32, i32* %13
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %16, %6
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
ret i32 %31
}

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