#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 EXIT_SUCCESS;
char *allocmem(char *, int);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(void) {
  char def_string[] = "C language programming";
  char *buffer = NULL;
  int size = strlen(def_string) + 1;
  buffer = allocmem(buffer, size);
  strcpy(buffer, def_string);
  *(buffer + --size) = '\0';
  printf("strlen(default): %d - %s\n", size, def_string);
  printf("   strlen(copy): %d - %s\n", strlen(buffer), buffer);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xea5(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xe9f(%rip),%ax
mov    %ax,-0xc(%rbp)
mov    0xe97(%rip),%al
mov    %al,-0xa(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <allocmem@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
mov    -0x28(%rbp),%rdx
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movaps 0xeb0(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x676e696d6d6172,%rax
mov    %rax,0xf(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%esi
xor    %edi,%edi
call   1060 <allocmem@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
movslq %r15d,%rsi
movb   $0x0,(%rbx,%rsi,1)
lea    0xe7f(%rip),%rdi
mov    %r14,%rdx
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe82(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1050 <printf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.def_string = [23 x i8] c"C language programming\00"
@.str = [26 x i8] c"strlen(default): %d - %s\0A\00"
@.str.1 = [26 x i8] c" strlen(copy): %d - %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [23 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [23 x i8]* %2 to i8*
store i8* null, i8** %3
%6 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 1
store i32 %8, i32* %4
%9 = load i8*, i8** %3
%10 = load i32, i32* %4
%11 = call i8* @allocmem(i8* %9, i32 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = add nsw i32 %16, -1
store i32 %17, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
store i8 0, i8* %19
%20 = load i32, i32* %4
%21 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = load i8*, i8** %3
%26 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %25)
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}

LLVM IR (-O2):
@__const.main.def_string = [23 x i8] c"C language programming\00"
@.str = [26 x i8] c"strlen(default): %d - %s\0A\00"
@.str.1 = [26 x i8] c" strlen(copy): %d - %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [23 x i8]
%2 = getelementptr inbounds [23 x i8], [23 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* %2)
%4 = add nsw i32 %3, 1
%5 = call i8* @allocmem(i8* null, i32 %4)
%6 = call i32 @strcpy(i8* %5, i8* %2)
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
store i8 0, i8* %8
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %2)
%10 = call i32 @strlen(i8* %5)
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %10, i8* %5)
%12 = load i32, i32* @EXIT_SUCCESS
ret i32 %12
}