#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 /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ ptr_diddle(char *);
char *strcat(char *, char *);
int main(void) {
  char *s = malloc(500);
  s = strcat(s, "1234");
  printf("Before = [%s]\n", s);
  ptr_diddle(s);
  printf("After = [%s]\n", s);
  free(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1f4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ptr_diddle@plt>
mov    -0x10(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1f4,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
movl   $0x34333231,(%rbx,%rax,1)
movb   $0x0,0x4(%rbx,%rax,1)
lea    0xe8c(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <ptr_diddle@plt>
lea    0xe84(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"1234\00"
@.str.1 = [15 x i8] c"Before = [%s]\0A\00"
@.str.2 = [14 x i8] c"After = [%s]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @malloc(i32 500)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @strcat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = call i32 @ptr_diddle(i8* %8)
%10 = load i8*, i8** %2
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %2
%13 = call i32 @free(i8* %12)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"1234\00"
@.str.1 = [15 x i8] c"Before = [%s]\0A\00"
@.str.2 = [14 x i8] c"After = [%s]\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(500) i8* @malloc(i32 500)
%2 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%3 = getelementptr i8, i8* %1, i64 %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %3, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5, i1 false)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%5 = tail call i32 @ptr_diddle(i8* %1)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%7 = tail call i32 @free(i8* %1)
ret i32 0
}