#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 */
scalar_t__ locate_status_arg(char const **, char const **);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int copy_status_arg(const char *cp, const char *ce, char *buf, int size) {
  if (locate_status_arg(&cp, &ce)) {
    int len = ce - cp;
    if (size - 1 < len)
      len = size - 1;
    memcpy(buf, cp, len);
    buf[len] = '\0';
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<copy_status_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <locate_status_arg@plt>
cmp    $0x0,%rax
je     119c <copy_status_arg+0x7c>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cmp    -0x28(%rbp),%eax
jge    1174 <copy_status_arg+0x54>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
jmp    11a3 <copy_status_arg+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_status_arg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rdi,0x8(%rsp)
mov    %rsi,(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <locate_status_arg@plt>
test   %rax,%rax
je     1173 <copy_status_arg+0x53>
mov    (%rsp),%eax
mov    0x8(%rsp),%rsi
sub    %esi,%eax
lea    -0x1(%rbx),%ebp
cmp    %ebx,%eax
cmovl  %eax,%ebp
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    $0x1,%eax
jmp    1175 <copy_status_arg+0x55>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @copy_status_arg(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
%7 = call i64 @locate_status_arg(i8** %5, i8** %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %4
%10 = load i8*, i8** %6
%11 = load i8*, i8** %5
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = icmp slt i32 %15, %3
%17 = add nsw i32 %3, -1
%18 = select i1 %16, i32 %15, i32 %17
%19 = call i32 @memcpy(i8* %2, i8* %11, i32 %18)
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %2, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %4, %9
%23 = phi i32 [ 1, %9 ], [ 0, %4 ]
ret i32 %23
}