#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);
char *realloc(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  char *foo, *bar;
  0;
  foo = malloc(123);
  ;
  foo = malloc(124);
  *foo = 'X';
  free(foo);
  printf("Should be X: '%c'\n", *foo);
  free(foo);
  foo = malloc(125);
  bar = realloc(foo, 126);
  *foo = 'X';
  free(bar);
  foo = malloc(127);
  ;
  *(foo - 1) = 'Z';
  free(foo);
  bar = "I'm going to eat you little fishie!";
  foo = malloc(strlen(bar));
  strcpy(foo, bar);
  free(foo);
  free(bar);
  0;
  0;
  return 42;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x7b,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x7c,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x58,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
lea    0xe53(%rip),%rdi
movsbl (%rax),%esi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x7d,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x7e,%esi
call   1080 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x58,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x7f,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x5a,-0x1(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xdff(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x2a,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x7c,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movb   $0x58,(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
movsbl (%rbx),%esi
lea    0xe7a(%rip),%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x7d,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x7e,%esi
call   1080 <realloc@plt>
movb   $0x58,(%rbx)
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x7f,%edi
call   1070 <malloc@plt>
movb   $0x5a,-0x1(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
lea    0xe3e(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x2a,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Should be X: '%c'\0A\00"
@.str.1 = [36 x i8] c"I'm going to eat you little fishie!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i8* @malloc(i32 123)
store i8* %8, i8** %6
%9 = call i8* @malloc(i32 124)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
store i8 88, i8* %10
%11 = load i8*, i8** %6
%12 = call i32 @free(i8* %11)
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 signext %14)
%16 = load i8*, i8** %6
%17 = call i32 @free(i8* %16)
%18 = call i8* @malloc(i32 125)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = call i8* @realloc(i8* %19, i32 126)
store i8* %20, i8** %7
%21 = load i8*, i8** %6
store i8 88, i8* %21
%22 = load i8*, i8** %7
%23 = call i32 @free(i8* %22)
%24 = call i8* @malloc(i32 127)
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 -1
store i8 90, i8* %26
%27 = load i8*, i8** %6
%28 = call i32 @free(i8* %27)
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8** %7
%29 = load i8*, i8** %7
%30 = call i32 @strlen(i8* %29)
%31 = call i8* @malloc(i32 %30)
store i8* %31, i8** %6
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = call i32 @strcpy(i8* %32, i8* %33)
%35 = load i8*, i8** %6
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %7
%38 = call i32 @free(i8* %37)
ret i32 42
}

LLVM IR (-O2):
@.str = [19 x i8] c"Should be X: '%c'\0A\00"
@.str.1 = [36 x i8] c"I'm going to eat you little fishie!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(124) i8* @malloc(i32 124)
store i8 88, i8* %3
%4 = tail call i32 @free(i8* %3)
%5 = load i8, i8* %3
%6 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8 signext %5)
%7 = tail call i32 @free(i8* %3)
%8 = tail call dereferenceable_or_null(125) i8* @malloc(i32 125)
%9 = tail call i8* @realloc(i8* %8, i32 126)
store i8 88, i8* %8
%10 = tail call i32 @free(i8* %9)
%11 = tail call dereferenceable_or_null(127) i8* @malloc(i32 127)
%12 = getelementptr inbounds i8, i8* %11, i64 -1
store i8 90, i8* %12
%13 = tail call i32 @free(i8* %11)
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i8* @malloc(i32 %14)
%16 = tail call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @free(i8* %15)
%18 = tail call i32 @free(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
ret i32 42
}