#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 mcmp(char *, char *, int);
int /*<<< orphan*/ mcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char *p;
  int v;
  p = malloc(128);
  mcpy(p, "hello world", 12);
  printf("%s\n", p);
  printf("memcmp = %d\n", mcmp(p, "hello world", 12));
  printf("memcmp = %d\n", mcmp(p, "hello xorld", 12));
  printf("memcmp = %d\n", mcmp(p, "hello yorld", 12));
  p[0] = -1;
  v = p[0];
  printf("%x %d %d %x\n", p[0], p[0], v, p[1]);
  printf("\0");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x80,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0xc,%edx
call   1060 <mcpy@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
mov    $0xc,%edx
call   1050 <mcmp@plt>
mov    %eax,%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
mov    $0xc,%edx
call   1050 <mcmp@plt>
mov    %eax,%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe50(%rip),%rsi
mov    $0xc,%edx
call   1050 <mcmp@plt>
mov    %eax,%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%r8d
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x80,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe98(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0xc,%edx
call   1070 <mcpy@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xc,%edx
call   1060 <mcmp@plt>
lea    0xe75(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
mov    $0xc,%edx
call   1060 <mcmp@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdi
mov    $0xc,%edx
call   1060 <mcmp@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0xff,(%rbx)
movsbl 0x1(%rbx),%r8d
lea    0xe3f(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0xffffffff,%edx
mov    $0xffffffff,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [13 x i8] c"memcmp = %d\0A\00"
@.str.3 = [12 x i8] c"hello xorld\00"
@.str.4 = [12 x i8] c"hello yorld\00"
@.str.5 = [13 x i8] c"%x %d %d %x\0A\00"
@.str.6 = [2 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i8* @malloc(i32 128)
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @mcpy(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 12)
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %2
%10 = call i32 @mcmp(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 12)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = load i8*, i8** %2
%13 = call i32 @mcmp(i8* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %2
%16 = call i32 @mcmp(i8* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 12)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 -1, i8* %19
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
store i32 %23, i32* %3
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = load i32, i32* %3
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %31, i32 %32, i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
@.str.2 = [13 x i8] c"memcmp = %d\0A\00"
@.str.3 = [12 x i8] c"hello xorld\00"
@.str.4 = [12 x i8] c"hello yorld\00"
@.str.5 = [13 x i8] c"%x %d %d %x\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%2 = tail call i32 @mcpy(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 12)
%3 = tail call i32 @puts(i8* dereferenceable(1) %1)
%4 = tail call i32 @mcmp(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 12)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%6 = tail call i32 @mcmp(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 12)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = tail call i32 @mcmp(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 12)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %8)
store i8 -1, i8* %1
%10 = getelementptr inbounds i8, i8* %1, i64 1
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 -1, i32 -1, i32 -1, i32 %12)
ret i32 0
}