#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 */
char *smm_alloc(int);
char *strcpy(char *, char const *);
int strlen(char const *);
char *csc_strcpy_alloc(const char *src, int extra) {
  char *dst;
  if (src == NULL) {
    return NULL;
  }
  extra = (extra + strlen(src) + 20) / 16 * 16;
  if ((dst = smm_alloc(extra)) == NULL) {
    return NULL;
  }
  return strcpy(dst, src);
}


x86 assembly (clang, -O0):
<csc_strcpy_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <csc_strcpy_alloc+0x27>
movq   $0x0,-0x8(%rbp)
jmp    11b2 <csc_strcpy_alloc+0x82>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x14,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <smm_alloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a1 <csc_strcpy_alloc+0x71>
movq   $0x0,-0x8(%rbp)
jmp    11b2 <csc_strcpy_alloc+0x82>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csc_strcpy_alloc>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1171 <csc_strcpy_alloc+0x41>
mov    %esi,%ebx
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%ecx
add    $0x14,%ecx
lea    (%rbx,%rax,1),%edi
add    $0x23,%edi
test   %ecx,%ecx
cmovns %ecx,%edi
and    $0xfffffff0,%edi
call   1050 <smm_alloc@plt>
test   %rax,%rax
je     1171 <csc_strcpy_alloc+0x41>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    1173 <csc_strcpy_alloc+0x43>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @csc_strcpy_alloc(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %26
10: ; preds = %2
%11 = load i32, i32* %5
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %11, %13
%15 = add nsw i32 %14, 20
%16 = sdiv i32 %15, 16
%17 = mul nsw i32 %16, 16
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = call i8* @smm_alloc(i32 %18)
store i8* %19, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %10
store i8* null, i8** %3
br label %26
22: ; preds = %10
%23 = load i8*, i8** %6
%24 = load i8*, i8** %4
%25 = call i8* @strcpy(i8* %23, i8* %24)
store i8* %25, i8** %3
br label %26
26: ; preds = %22, %21, %9
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
define i8* @csc_strcpy_alloc(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = add i32 %1, 20
%7 = add i32 %6, %5
%8 = sdiv i32 %7, 16
%9 = shl nsw i32 %8, 4
%10 = tail call i8* @smm_alloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %4
%13 = tail call i8* @strcpy(i8* %10, i8* %0)
br label %14
14: ; preds = %4, %2, %12
%15 = phi i8* [ %10, %12 ], [ null, %2 ], [ null, %4 ]
ret i8* %15
}