#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*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *FP_strdup(char *string) {
  char *result;
  if (string == NULL)
    return NULL;
  if ((result = (char *)malloc(strlen(string) + 1)) == NULL) {
    fprintf(stderr, "proccgi -- out of memory dupping %d bytes\n",
            (int)strlen(string));
    return NULL;
  }
  strcpy(result, string);
  return result;
}


x86 assembly (clang, -O0):
<FP_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <FP_strdup+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11cf <FP_strdup+0x8f>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ba <FP_strdup+0x7a>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cf <FP_strdup+0x8f>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FP_strdup>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1190 <FP_strdup+0x50>
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     116f <FP_strdup+0x2f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    1192 <FP_strdup+0x52>
mov    0x2e6a(%rip),%rax
mov    (%rax),%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xe79(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1050 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"proccgi -- out of memory dupping %d bytes\0A\00"
define i8* @FP_strdup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %26
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 1
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* %17)
%19 = trunc i64 %18 to i32
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %19)
store i8* null, i8** %2
br label %26
21: ; preds = %8
%22 = load i8*, i8** %4
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %4
store i8* %25, i8** %2
br label %26
26: ; preds = %21, %15, %7
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"proccgi -- out of memory dupping %d bytes\0A\00"
define i8* @FP_strdup(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = add nsw i64 %4, 1
%6 = tail call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i64 @strlen(i8* %0)
%12 = trunc i64 %11 to i32
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %16
14: ; preds = %3
%15 = tail call i32 @strcpy(i8* %7, i8* %0)
br label %16
16: ; preds = %1, %14, %9
%17 = phi i8* [ null, %9 ], [ %7, %14 ], [ null, %1 ]
ret i8* %17
}