#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__ malloc(int);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *getTextByWords(char *text, char *words) {
  if (text == NULL)
    return NULL;
  char *s = (char *)malloc(sizeof(char) * strlen(text));
  strncpy(s, text, strlen(text) + 1);
  s[strlen(text)] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<getTextByWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <getTextByWords+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11c0 <getTextByWords+0x90>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTextByWords>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1170 <getTextByWords+0x40>
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
jmp    1173 <getTextByWords+0x43>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @getTextByWords(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %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 %29
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
%13 = mul i64 1, %12
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = load i8*, i8** %4
%20 = call i64 @strlen(i8* %19)
%21 = add i64 %20, 1
%22 = trunc i64 %21 to i32
%23 = call i32 @strncpy(i8* %17, i8* %18, i32 %22)
%24 = load i8*, i8** %6
%25 = load i8*, i8** %4
%26 = call i64 @strlen(i8* %25)
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 0, i8* %27
%28 = load i8*, i8** %6
store i8* %28, i8** %3
br label %29
29: ; preds = %10, %9
%30 = load i8*, i8** %3
ret i8* %30
}

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