#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 *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  char staticMemory[100];
  char *dynamicMemory;
  strcpy(staticMemory, "Short string of text.\n");
  dynamicMemory = malloc(200 * sizeof(char));
  if (dynamicMemory == NULL) {
    printf("Unable to allocate.\n");
  } else {
    strcpy(dynamicMemory, "Long string of text.\n");
  }
  printf("1st: %s\n", staticMemory);
  printf("2nd: %s\n", dynamicMemory);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xeb3(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0xc8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    117e <main+0x4e>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    118e <main+0x5e>
mov    -0x78(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
lea    0xeb4(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    $0xc8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1177 <main+0x37>
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    1183 <main+0x43>
lea    0xec1(%rip),%rdi
call   1040 <puts@plt>
lea    0xea3(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Short string of text.\0A\00"
@.str.1 = [21 x i8] c"Unable to allocate.\0A\00"
@.str.2 = [22 x i8] c"Long string of text.\0A\00"
@.str.3 = [9 x i8] c"1st: %s\0A\00"
@.str.4 = [9 x i8] c"2nd: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i8* @malloc(i32 200)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %14
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %11, %9
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Short string of text.\0A\00"
@.str.2 = [22 x i8] c"Long string of text.\0A\00"
@.str.3 = [9 x i8] c"1st: %s\0A\00"
@.str.4 = [9 x i8] c"2nd: %s\0A\00"
@str = [20 x i8] c"Unable to allocate.\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = call dereferenceable_or_null(200) i8* @malloc(i32 200)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %10
8: ; preds = %0
%9 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %4)
ret i32 0
}