#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*/ ft_strncpy(char *, char const *, int);
int ft_wdlen(char const *, char);
scalar_t__ malloc(int);
char *ft_wdncpy(const char *src, char c) {
  char *item;
  int len;
  len = ft_wdlen(src, c);
  item = (char *)malloc(sizeof(char) * (len + 1));
  if (!item)
    return (NULL);
  ft_strncpy(item, src, len);
  item[len] = '\0';
  return (item);
}


x86 assembly (clang, -O0):
<ft_wdncpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <ft_wdlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1181 <ft_wdncpy+0x51>
movq   $0x0,-0x8(%rbp)
jmp    11a5 <ft_wdncpy+0x75>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <ft_strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_wdncpy>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <ft_wdlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1168 <ft_wdncpy+0x38>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <ft_strncpy@plt>
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    116a <ft_wdncpy+0x3a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ft_wdncpy(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
%8 = load i8*, i8** %4
%9 = load i8, i8* %5
%10 = call i32 @ft_wdlen(i8* %8, i8 signext %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = mul i64 1, %13
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %2
store i8* null, i8** %3
br label %31
21: ; preds = %2
%22 = load i8*, i8** %6
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = call i32 @ft_strncpy(i8* %22, i8* %23, i32 %24)
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %6
store i8* %30, i8** %3
br label %31
31: ; preds = %21, %20
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
define i8* @ft_wdncpy(i8* %0, i8 signext %1) {
%3 = tail call i32 @ft_wdlen(i8* %0, i8 signext %1)
%4 = add nsw i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = tail call i32 @ft_strncpy(i8* %6, i8* %0, i32 %3)
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %2, %8
%13 = phi i8* [ %6, %8 ], [ null, %2 ]
ret i8* %13
}