#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 **);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *dup_status_arg(const char *cp, const char *ce) {
  char *ret = NULL;
  if (locate_status_arg(&cp, &ce)) {
    ret = malloc(ce - cp + 1);
    if (ret) {
      memcpy(ret, cp, ce - cp);
      ret[ce - cp] = '\0';
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<dup_status_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <locate_status_arg@plt>
cmp    $0x0,%rax
je     11b6 <dup_status_arg+0x86>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b1 <dup_status_arg+0x81>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11b6 <dup_status_arg+0x86>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dup_status_arg>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
mov    %rsi,(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <locate_status_arg@plt>
test   %rax,%rax
je     118e <dup_status_arg+0x5e>
mov    (%rsp),%r14d
mov    0x8(%rsp),%r15
sub    %r15d,%r14d
lea    0x1(%r14),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     118e <dup_status_arg+0x5e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
mov    (%rsp),%rax
sub    0x8(%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
jmp    1190 <dup_status_arg+0x60>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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