#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 */
typedef scalar_t__ wchar_t;

/* Variables and functions */
scalar_t__ calloc(int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ realloc(int /*<<< orphan*/ *, int);
char *strdup(char *);
scalar_t__ *wcsdup(char *);
char *c_leaks(void) {
  char *strdup_leak = strdup("leak 1");
  strdup_leak[1] = 0;
  printf("%s\n", strdup_leak);
  char *malloc_leak = (char *)malloc(60);
  malloc_leak[0] = 'm';
  malloc_leak[1] = 0;
  printf("%s\n", malloc_leak);
  char *realloc_leak = (char *)realloc(NULL, 100);
  realloc_leak[0] = 'r';
  realloc_leak[1] = 0;
  printf("%s\n", realloc_leak);
  wchar_t *wcsdup_leak = wcsdup(L"leak 2");
  wcsdup_leak[1] = 0;
  printf("%s\n", (char *)wcsdup_leak);
  char *calloc_leak = (char *)calloc(3, 200);
  calloc_leak[0] = 'c';
  calloc_leak[1] = 0;
  printf("%s\n", calloc_leak);
  return (malloc_leak);
}


x86 assembly (clang, -O0):
<c_leaks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x3c,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x6d,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x64,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x72,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
lea    0xe17(%rip),%rdi
call   1060 <wcsdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x20(%rbp),%rsi
lea    0xdf2(%rip),%rdi
call   1030 <printf@plt>
mov    $0x3,%edi
mov    $0xc8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x63,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x28(%rbp),%rsi
lea    0xdc0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_leaks>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
call   1080 <strdup@plt>
movb   $0x0,0x1(%rax)
lea    0xe8c(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x3c,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movw   $0x6d,(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
mov    $0x64,%esi
call   1070 <realloc@plt>
movw   $0x72,(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xe46(%rip),%rdi
call   1060 <wcsdup@plt>
movq   $0x0,0x8(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x3,%edi
mov    $0xc8,%esi
call   1040 <calloc@plt>
movw   $0x63,(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"leak 1\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [7 x i32] [i32 108, i32 101, i32 97, i32 107, i32 32, i32 50, i32 0]
define i8* @c_leaks() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i8*
%6 = call i8* @strdup(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %1
%7 = load i8*, i8** %1
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8 0, i8* %8
%9 = load i8*, i8** %1
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i64 @malloc(i32 60)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 109, i8* %14
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %16
%17 = load i8*, i8** %2
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i64 @realloc(i32* null, i32 100)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 114, i8* %22
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8 0, i8* %24
%25 = load i8*, i8** %3
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = call i64* @wcsdup(i8* bitcast ([7 x i32]* @.str.2 to i8*))
store i64* %27, i64** %4
%28 = load i64*, i64** %4
%29 = getelementptr inbounds i64, i64* %28, i64 1
store i64 0, i64* %29
%30 = load i64*, i64** %4
%31 = bitcast i64* %30 to i8*
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i64 @calloc(i32 3, i32 200)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %5
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 0
store i8 99, i8* %36
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8 0, i8* %38
%39 = load i8*, i8** %5
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@.str = [7 x i8] c"leak 1\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [7 x i32] [i32 108, i32 101, i32 97, i32 107, i32 32, i32 50, i32 0]
define i8* @c_leaks() {
%1 = tail call dereferenceable_or_null(7) i8* @strdup(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%2 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %2
%3 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%4 = tail call i64 @malloc(i32 60)
%5 = inttoptr i64 %4 to i8*
store i8 109, i8* %5
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8 0, i8* %6
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%8 = tail call i64 @realloc(i32* null, i32 100)
%9 = inttoptr i64 %8 to i8*
store i8 114, i8* %9
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 0, i8* %10
%11 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%12 = tail call i64* @wcsdup(i8* bitcast ([7 x i32]* @.str.2 to i8*))
%13 = getelementptr inbounds i64, i64* %12, i64 1
store i64 0, i64* %13
%14 = bitcast i64* %12 to i8*
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = tail call i64 @calloc(i32 3, i32 200)
%17 = inttoptr i64 %16 to i8*
store i8 99, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 0, i8* %18
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
ret i8* %5
}