#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*/ exit(int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *, int);
unsigned char *realloc(unsigned char *, int);
int main() {
  unsigned char *ptr;
  int i;
  ptr = malloc(123);
  for (i = 0; i < 123; i++) {
    if (ptr[i] != 0xDD) {
      printf(
          "malloc: Allocated memory is not initialized with 0xDD. offset %d\n",
          i);
      exit(1);
    }
  }
  ptr = realloc(ptr, 500);
  for (i = 0; i < 500; i++) {
    if (ptr[i] != 0xDD) {
      printf(
          "realloc: Allocated memory is not initialized with 0xDD. offset %d\n",
          i);
      exit(1);
    }
  }
  free(ptr);
  for (i = 0; i < 123; i++) {
    if (ptr[i] != 0xEE) {
      printf("free: Freed memory is not initialized with 0xEE. offset %d\n", i);
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x7b,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x7b,-0x14(%rbp)
jge    11c1 <main+0x71>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xdd,%eax
je     11ae <main+0x5e>
mov    -0x14(%rbp),%esi
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11b3 <main+0x63>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1174 <main+0x24>
mov    -0x10(%rbp),%rdi
mov    $0x1f4,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1f4,-0x14(%rbp)
jge    122a <main+0xda>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xdd,%eax
je     1217 <main+0xc7>
mov    -0x14(%rbp),%esi
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    121c <main+0xcc>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11da <main+0x8a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x7b,-0x14(%rbp)
jge    1287 <main+0x137>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xee,%eax
je     1274 <main+0x124>
mov    -0x14(%rbp),%esi
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1279 <main+0x129>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123a <main+0xea>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x7b,%edi
call   1050 <malloc@plt>
xor    %esi,%esi
test   %sil,%sil
jne    123f <main+0xef>
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
cmpb   $0xdd,0x1(%rax,%rcx,1)
jne    1232 <main+0xe2>
cmpb   $0xdd,0x2(%rax,%rcx,1)
jne    1238 <main+0xe8>
cmp    $0x78,%rcx
je     119f <main+0x4f>
lea    0x3(%rcx),%rsi
cmpb   $0xdd,0x3(%rax,%rcx,1)
mov    %rsi,%rcx
je     1170 <main+0x20>
jmp    123f <main+0xef>
mov    %rax,%rdi
mov    $0x1f4,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
mov    $0x4,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0xdd,-0x4(%rbx,%rsi,1)
jne    1248 <main+0xf8>
cmpb   $0xdd,-0x3(%rbx,%rsi,1)
jne    1255 <main+0x105>
cmpb   $0xdd,-0x2(%rbx,%rsi,1)
jne    1262 <main+0x112>
cmpb   $0xdd,-0x1(%rbx,%rsi,1)
jne    126f <main+0x11f>
cmpb   $0xdd,(%rbx,%rsi,1)
jne    1273 <main+0x123>
add    $0x5,%rsi
cmp    $0x1f8,%rsi
jne    11c0 <main+0x70>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x2,%esi
cmpb   $0xee,-0x2(%rbx,%rsi,1)
jne    1282 <main+0x132>
cmpb   $0xee,-0x1(%rbx,%rsi,1)
jne    127c <main+0x12c>
cmpb   $0xee,(%rbx,%rsi,1)
jne    1286 <main+0x136>
add    $0x3,%rsi
cmp    $0x7d,%rsi
jne    1210 <main+0xc0>
xor    %eax,%eax
pop    %rbx
ret
add    $0x1,%rcx
jmp    123c <main+0xec>
add    $0x2,%rcx
mov    %rcx,%rsi
lea    0xdba(%rip),%rdi
jmp    128d <main+0x13d>
add    $0xfffffffffffffffc,%rsi
lea    0xdef(%rip),%rdi
jmp    128d <main+0x13d>
add    $0xfffffffffffffffd,%rsi
lea    0xde2(%rip),%rdi
jmp    128d <main+0x13d>
add    $0xfffffffffffffffe,%rsi
lea    0xdd5(%rip),%rdi
jmp    128d <main+0x13d>
add    $0xffffffffffffffff,%rsi
lea    0xdc8(%rip),%rdi
jmp    128d <main+0x13d>
add    $0xffffffffffffffff,%rsi
jmp    1286 <main+0x136>
add    $0xfffffffffffffffe,%rsi
lea    0xdf8(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [66 x i8] c"malloc: Allocated memory is not initialized with 0xDD. offset %d\0A\00"
@.str.1 = [67 x i8] c"realloc: Allocated memory is not initialized with 0xDD. offset %d\0A\00"
@.str.2 = [60 x i8] c"free: Freed memory is not initialized with 0xEE. offset %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i8* @malloc(i32 123)
store i8* %4, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %21, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 123
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp ne i32 %14, 221
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = load i32, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %8
br label %21
21: ; preds = %20
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %5
24: ; preds = %5
%25 = load i8*, i8** %2
%26 = call i8* @realloc(i8* %25, i32 500)
store i8* %26, i8** %2
store i32 0, i32* %3
br label %27
27: ; preds = %43, %24
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 500
br i1 %29, label %30, label %46
30: ; preds = %27
%31 = load i8*, i8** %2
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = icmp ne i32 %36, 221
br i1 %37, label %38, label %42
38: ; preds = %30
%39 = load i32, i32* %3
%40 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %30
br label %43
43: ; preds = %42
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %27
46: ; preds = %27
%47 = load i8*, i8** %2
%48 = call i32 @free(i8* %47)
store i32 0, i32* %3
br label %49
49: ; preds = %65, %46
%50 = load i32, i32* %3
%51 = icmp slt i32 %50, 123
br i1 %51, label %52, label %68
52: ; preds = %49
%53 = load i8*, i8** %2
%54 = load i32, i32* %3
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = icmp ne i32 %58, 238
br i1 %59, label %60, label %64
60: ; preds = %52
%61 = load i32, i32* %3
%62 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %61)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %52
br label %65
65: ; preds = %64
%66 = load i32, i32* %3
%67 = add nsw i32 %66, 1
store i32 %67, i32* %3
br label %49
68: ; preds = %49
ret i32 0
}

LLVM IR (-O2):
@.str = [66 x i8] c"malloc: Allocated memory is not initialized with 0xDD. offset %d\0A\00"
@.str.1 = [67 x i8] c"realloc: Allocated memory is not initialized with 0xDD. offset %d\0A\00"
@.str.2 = [60 x i8] c"free: Freed memory is not initialized with 0xEE. offset %d\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(123) i8* @malloc(i32 123)
br i1 undef, label %9, label %5
2: ; preds = %23, %15, %9
%3 = phi i64 [ %11, %9 ], [ %16, %15 ], [ %21, %23 ]
%4 = trunc i64 %3 to i32
br label %5
5: ; preds = %2, %0
%6 = phi i32 [ %4, %2 ], [ 0, %0 ]
%7 = tail call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0, %23
%10 = phi i64 [ %21, %23 ], [ 0, %0 ]
%11 = add nuw nsw i64 %10, 1
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, -35
br i1 %14, label %15, label %2
15: ; preds = %9
%16 = add nuw nsw i64 %10, 2
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, -35
br i1 %19, label %20, label %2
20: ; preds = %15
%21 = add nuw nsw i64 %10, 3
%22 = icmp eq i64 %21, 123
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %1, i64 %21
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, -35
br i1 %26, label %9, label %2
27: ; preds = %20
%28 = tail call i8* @realloc(i8* %1, i32 500)
br label %29
29: ; preds = %59, %27
%30 = phi i64 [ 0, %27 ], [ %60, %59 ]
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, -35
br i1 %33, label %39, label %34
34: ; preds = %54, %49, %44, %39, %29
%35 = phi i64 [ %30, %29 ], [ %40, %39 ], [ %45, %44 ], [ %50, %49 ], [ %55, %54 ]
%36 = trunc i64 %35 to i32
%37 = tail call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %29
%40 = add nuw nsw i64 %30, 1
%41 = getelementptr inbounds i8, i8* %28, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, -35
br i1 %43, label %44, label %34
44: ; preds = %39
%45 = add nuw nsw i64 %30, 2
%46 = getelementptr inbounds i8, i8* %28, i64 %45
%47 = load i8, i8* %46
%48 = icmp eq i8 %47, -35
br i1 %48, label %49, label %34
49: ; preds = %44
%50 = add nuw nsw i64 %30, 3
%51 = getelementptr inbounds i8, i8* %28, i64 %50
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, -35
br i1 %53, label %54, label %34
54: ; preds = %49
%55 = add nuw nsw i64 %30, 4
%56 = getelementptr inbounds i8, i8* %28, i64 %55
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, -35
br i1 %58, label %59, label %34
59: ; preds = %54
%60 = add nuw nsw i64 %30, 5
%61 = icmp eq i64 %60, 500
br i1 %61, label %62, label %29
62: ; preds = %59
%63 = tail call i32 @free(i8* %28)
br label %64
64: ; preds = %84, %62
%65 = phi i64 [ 0, %62 ], [ %85, %84 ]
%66 = getelementptr inbounds i8, i8* %28, i64 %65
%67 = load i8, i8* %66
%68 = icmp eq i8 %67, -18
br i1 %68, label %74, label %69
69: ; preds = %79, %74, %64
%70 = phi i64 [ %65, %64 ], [ %75, %74 ], [ %80, %79 ]
%71 = trunc i64 %70 to i32
%72 = tail call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %71)
%73 = tail call i32 @exit(i32 1)
unreachable
74: ; preds = %64
%75 = add nuw nsw i64 %65, 1
%76 = getelementptr inbounds i8, i8* %28, i64 %75
%77 = load i8, i8* %76
%78 = icmp eq i8 %77, -18
br i1 %78, label %79, label %69
79: ; preds = %74
%80 = add nuw nsw i64 %65, 2
%81 = getelementptr inbounds i8, i8* %28, i64 %80
%82 = load i8, i8* %81
%83 = icmp eq i8 %82, -18
br i1 %83, label %84, label %69
84: ; preds = %79
%85 = add nuw nsw i64 %65, 3
%86 = icmp eq i64 %85, 123
br i1 %86, label %87, label %64
87: ; preds = %84
ret i32 0
}