#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strlcpy(char *, char const *, int);
int strlen(char const *);
char *stranow(const char *s) {
  char *p;
  int i;
  if (!s)
    return 0;
  i = strlen(s);
  p = (char *)malloc(sizeof(char) * (i + 1));
  if (!p)
    return 0;
  if (!strlcpy(p, s, (i + 1))) {
    if (p)
      free(p);
    return 0;
  }
  return p;
}


x86 assembly (clang, -O0):
<stranow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <stranow+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <stranow+0xa4>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119f <stranow+0x5f>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <stranow+0xa4>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1060 <strlcpy@plt>
cmp    $0x0,%eax
jne    11dc <stranow+0x9c>
cmpq   $0x0,-0x18(%rbp)
je     11cf <stranow+0x8f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <stranow+0xa4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stranow>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     117e <stranow+0x3e>
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     117e <stranow+0x3e>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <strlcpy@plt>
test   %eax,%eax
jne    1181 <stranow+0x41>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @stranow(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = tail call i32 @strlcpy(i8* %7, i8* %0, i32 %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @free(i8* %7)
br label %14
14: ; preds = %9, %3, %1, %12
%15 = phi i8* [ null, %12 ], [ null, %1 ], [ null, %3 ], [ %7, %9 ]
ret i8* %15
}