int main() {
  char *hello = (char *)malloc(16 * sizeof(char));
  char *world = (char *)malloc(7 * sizeof(char));
  _strcpy(hello, "hello ");
  _strcpy(world, "world!");
  printf("strings: a: %s\nb:%s\n\n", hello, world);
  printf("length: %d, %d\n", _strlen(hello), _strlen(world));
  printf("compare: %s\n\n", (_strcmp(hello, world)) == 0 ? "true" : "false");
  _strcat(hello, world);
  printf("after strcat: strings: a: %s\nb:%s\n", hello, world);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x7,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1060 <_strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1060 <_strcpy@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <_strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1040 <_strlen@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1030 <_strcmp@plt>
mov    %eax,%ecx
lea    0xe3e(%rip),%rsi
lea    0xe32(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1080 <_strcat@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x7,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe7b(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <_strcpy@plt>
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <_strcpy@plt>
lea    0xe67(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <_strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <_strlen@plt>
lea    0xe53(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <_strcmp@plt>
test   %eax,%eax
lea    0xe50(%rip),%rax
lea    0xe4e(%rip),%rsi
cmove  %rax,%rsi
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <_strcat@plt>
lea    0xe2e(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"hello \00"
@.str.1 = [7 x i8] c"world!\00"
@.str.2 = [22 x i8] c"strings: a: %s\0Ab:%s\0A\0A\00"
@.str.3 = [16 x i8] c"length: %d, %d\0A\00"
@.str.4 = [14 x i8] c"compare: %s\0A\0A\00"
@.str.5 = [5 x i8] c"true\00"
@.str.6 = [6 x i8] c"false\00"
@.str.7 = [35 x i8] c"after strcat: strings: a: %s\0Ab:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @malloc(i64 16)
store i8* %4, i8** %2
%5 = call i8* @malloc(i64 7)
store i8* %5, i8** %3
%6 = load i8*, i8** %2
%7 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @_strcpy to i32 (i8*, i8*, ...)*)(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %3
%9 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @_strcpy to i32 (i8*, i8*, ...)*)(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = load i8*, i8** %2
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %10, i8* %11)
%13 = load i8*, i8** %2
%14 = call i32 (i8*, ...) bitcast (i32 (...)* @_strlen to i32 (i8*, ...)*)(i8* %13)
%15 = load i8*, i8** %3
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @_strlen to i32 (i8*, ...)*)(i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %16)
%18 = load i8*, i8** %2
%19 = load i8*, i8** %3
%20 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @_strcmp to i32 (i8*, i8*, ...)*)(i8* %18, i8* %19)
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %2
%26 = load i8*, i8** %3
%27 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @_strcat to i32 (i8*, i8*, ...)*)(i8* %25, i8* %26)
%28 = load i8*, i8** %2
%29 = load i8*, i8** %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %28, i8* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"hello \00"
@.str.1 = [7 x i8] c"world!\00"
@.str.2 = [22 x i8] c"strings: a: %s\0Ab:%s\0A\0A\00"
@.str.3 = [16 x i8] c"length: %d, %d\0A\00"
@.str.4 = [14 x i8] c"compare: %s\0A\0A\00"
@.str.5 = [5 x i8] c"true\00"
@.str.6 = [6 x i8] c"false\00"
@.str.7 = [35 x i8] c"after strcat: strings: a: %s\0Ab:%s\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(16) i8* @malloc(i64 16)
%2 = tail call dereferenceable_or_null(7) i8* @malloc(i64 7)
%3 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @_strcpy to i32 (i8*, i8*, ...)*)(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @_strcpy to i32 (i8*, i8*, ...)*)(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @_strlen to i32 (i8*, ...)*)(i8* %1)
%7 = tail call i32 (i8*, ...) bitcast (i32 (...)* @_strlen to i32 (i8*, ...)*)(i8* %2)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %6, i32 %7)
%9 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @_strcmp to i32 (i8*, i8*, ...)*)(i8* %1, i8* %2)
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%13 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @_strcat to i32 (i8*, i8*, ...)*)(i8* %1, i8* %2)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %1, i8* %2)
ret i32 0
}