#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(int *);
scalar_t__ malloc(int);
int *jerasure_erasures_to_erased(int k, int m, int *erasures) {
  int td;
  int t_non_erased;
  int *erased;
  int i;
  td = k + m;
  erased = (int *)malloc(sizeof(int) * (td));
  if (erased == NULL)
    return NULL;
  t_non_erased = td;
  for (i = 0; i < td; i++)
    erased[i] = 0;
  for (i = 0; erasures[i] != -1; i++) {
    if (erased[erasures[i]] == 0) {
      erased[erasures[i]] = 1;
      t_non_erased--;
      if (t_non_erased < k) {
        free(erased);
        return NULL;
      }
    }
  }
  return erased;
}


x86 assembly (clang, -O0):
<jerasure_erasures_to_erased>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1166 <jerasure_erasures_to_erased+0x46>
movq   $0x0,-0x8(%rbp)
jmp    1231 <jerasure_erasures_to_erased+0x111>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    119c <jerasure_erasures_to_erased+0x7c>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1173 <jerasure_erasures_to_erased+0x53>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
je     1229 <jerasure_erasures_to_erased+0x109>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1216 <jerasure_erasures_to_erased+0xf6>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1211 <jerasure_erasures_to_erased+0xf1>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1231 <jerasure_erasures_to_erased+0x111>
jmp    1216 <jerasure_erasures_to_erased+0xf6>
jmp    121b <jerasure_erasures_to_erased+0xfb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a3 <jerasure_erasures_to_erased+0x83>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jerasure_erasures_to_erased>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%ebp
add    %edi,%r15d
lea    0x0(,%r15,4),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11af <jerasure_erasures_to_erased+0x7f>
mov    %rax,%r14
test   %r15d,%r15d
jle    1172 <jerasure_erasures_to_erased+0x42>
lea    -0x1(%r15),%eax
lea    0x4(,%rax,4),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    (%rbx),%eax
cmp    $0xffffffff,%eax
je     11b2 <jerasure_erasures_to_erased+0x82>
add    $0x4,%rbx
jmp    118b <jerasure_erasures_to_erased+0x5b>
nop
mov    (%rbx),%eax
add    $0x4,%rbx
cmp    $0xffffffff,%eax
je     11b2 <jerasure_erasures_to_erased+0x82>
cltq
cmpl   $0x0,(%r14,%rax,4)
jne    1180 <jerasure_erasures_to_erased+0x50>
movl   $0x1,(%r14,%rax,4)
cmp    %ebp,%r15d
jle    11a7 <jerasure_erasures_to_erased+0x77>
add    $0xffffffff,%r15d
jmp    1180 <jerasure_erasures_to_erased+0x50>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @jerasure_erasures_to_erased(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = add nsw i32 %12, %13
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = mul i64 4, %16
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %10
%21 = load i32*, i32** %10
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %24
23: ; preds = %3
store i32* null, i32** %4
br label %81
24: ; preds = %3
%25 = load i32, i32* %8
store i32 %25, i32* %9
store i32 0, i32* %11
br label %26
26: ; preds = %35, %24
%27 = load i32, i32* %11
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i32*, i32** %10
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 0, i32* %34
br label %35
35: ; preds = %30
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
store i32 %37, i32* %11
br label %26
38: ; preds = %26
store i32 0, i32* %11
br label %39
39: ; preds = %76, %38
%40 = load i32*, i32** %7
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = icmp ne i32 %44, -1
br i1 %45, label %46, label %79
46: ; preds = %39
%47 = load i32*, i32** %10
%48 = load i32*, i32** %7
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
%52 = load i32, i32* %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %47, i64 %53
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %75
57: ; preds = %46
%58 = load i32*, i32** %10
%59 = load i32*, i32** %7
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %58, i64 %64
store i32 1, i32* %65
%66 = load i32, i32* %9
%67 = add nsw i32 %66, -1
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = load i32, i32* %5
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %74
71: ; preds = %57
%72 = load i32*, i32** %10
%73 = call i32 @free(i32* %72)
store i32* null, i32** %4
br label %81
74: ; preds = %57
br label %75
75: ; preds = %74, %46
br label %76
76: ; preds = %75
%77 = load i32, i32* %11
%78 = add nsw i32 %77, 1
store i32 %78, i32* %11
br label %39
79: ; preds = %39
%80 = load i32*, i32** %10
store i32* %80, i32** %4
br label %81
81: ; preds = %79, %71, %23
%82 = load i32*, i32** %4
ret i32* %82
}

LLVM IR (-O2):
define i32* @jerasure_erasures_to_erased(i32 %0, i32 %1, i32* nocapture %2) {
%4 = add i32 %1, %0
%5 = shl i32 %4, 2
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i32*
%8 = inttoptr i64 %6 to i8*
%9 = icmp eq i64 %6, 0
br i1 %9, label %39, label %10
10: ; preds = %3
%11 = icmp sgt i32 %4, 0
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = add nsw i32 %4, -1
%14 = zext i32 %13 to i64
%15 = shl nuw nsw i64 %14, 2
%16 = add nuw nsw i64 %15, 4
br label %17
17: ; preds = %12, %10
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, -1
br i1 %19, label %39, label %20
20: ; preds = %17, %33
%21 = phi i64 [ %35, %33 ], [ 0, %17 ]
%22 = phi i32 [ %37, %33 ], [ %18, %17 ]
%23 = phi i32 [ %34, %33 ], [ %4, %17 ]
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i32, i32* %7, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %20
store i32 1, i32* %25
%29 = add nsw i32 %23, -1
%30 = icmp sgt i32 %23, %0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = tail call i32 @free(i32* %7)
br label %39
33: ; preds = %20, %28
%34 = phi i32 [ %29, %28 ], [ %23, %20 ]
%35 = add nuw i64 %21, 1
%36 = getelementptr inbounds i32, i32* %2, i64 %35
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %20
39: ; preds = %33, %17, %3, %31
%40 = phi i32* [ null, %31 ], [ null, %3 ], [ %7, %17 ], [ %7, %33 ]
ret i32* %40
}