#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 int /*<<< orphan*/ test_num2;
typedef int /*<<< orphan*/ test_num;
struct sparse_array {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sparse_array_free(struct sparse_array *);
scalar_t__ sparse_array_get(struct sparse_array *, int /*<<< orphan*/,
                            int /*<<< orphan*/ *);
struct sparse_array *sparse_array_init(int, int);
int /*<<< orphan*/ sparse_array_set(struct sparse_array *, int /*<<< orphan*/,
                                    int const *, int);
int test_array_set_overwrites_old_values() {
  struct sparse_array *arr = NULL;
  const int test_num = 666;
  const int test_num2 = 1024;
  arr = sparse_array_init(sizeof(int), 150);
  if (!(arr)) {
    printf("%i: ", 156);
    return 0;
  };
  if (!(sparse_array_set(arr, 0, &test_num, sizeof(test_num)))) {
    printf("%i: ", 158);
    return 0;
  };
  if (!(sparse_array_set(arr, 0, &test_num2, sizeof(test_num2)))) {
    printf("%i: ", 159);
    return 0;
  };
  if (!(*(const int *)sparse_array_get(arr, 0, NULL) == 1024)) {
    printf("%i: ", 161);
    return 0;
  };
  if (!(sparse_array_free(arr))) {
    printf("%i: ", 163);
    return 0;
  };
  return 1;
}


x86 assembly (clang, -O0):
<test_array_set_overwrites_old_values>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movl   $0x29a,-0x14(%rbp)
movl   $0x400,-0x18(%rbp)
mov    $0x4,%edi
mov    $0x96,%esi
call   1070 <sparse_array_init@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a9 <test_array_set_overwrites_old_values+0x59>
lea    0xe6d(%rip),%rdi
mov    $0x9c,%esi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128b <test_array_set_overwrites_old_values+0x13b>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
lea    -0x14(%rbp),%rdx
mov    $0x4,%ecx
call   1030 <sparse_array_set@plt>
cmp    $0x0,%eax
jne    11e3 <test_array_set_overwrites_old_values+0x93>
lea    0xe33(%rip),%rdi
mov    $0x9e,%esi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128b <test_array_set_overwrites_old_values+0x13b>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
lea    -0x18(%rbp),%rdx
mov    $0x4,%ecx
call   1030 <sparse_array_set@plt>
cmp    $0x0,%eax
jne    121d <test_array_set_overwrites_old_values+0xcd>
lea    0xdf9(%rip),%rdi
mov    $0x9f,%esi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128b <test_array_set_overwrites_old_values+0x13b>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <sparse_array_get@plt>
cmpl   $0x400,(%rax)
je     1255 <test_array_set_overwrites_old_values+0x105>
lea    0xdc1(%rip),%rdi
mov    $0xa1,%esi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128b <test_array_set_overwrites_old_values+0x13b>
mov    -0x10(%rbp),%rdi
call   1050 <sparse_array_free@plt>
cmp    $0x0,%eax
jne    1284 <test_array_set_overwrites_old_values+0x134>
lea    0xd92(%rip),%rdi
mov    $0xa3,%esi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128b <test_array_set_overwrites_old_values+0x13b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_array_set_overwrites_old_values>:
push   %rbp
push   %rbx
push   %rax
movl   $0x29a,0x4(%rsp)
movl   $0x400,(%rsp)
mov    $0x4,%edi
mov    $0x96,%esi
call   1070 <sparse_array_init@plt>
test   %rax,%rax
je     11de <test_array_set_overwrites_old_values+0x8e>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x4,%ecx
call   1030 <sparse_array_set@plt>
test   %eax,%eax
je     11ec <test_array_set_overwrites_old_values+0x9c>
xor    %ebp,%ebp
mov    %rsp,%rdx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%ecx
call   1030 <sparse_array_set@plt>
test   %eax,%eax
je     11ff <test_array_set_overwrites_old_values+0xaf>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <sparse_array_get@plt>
cmpl   $0x400,(%rax)
jne    1212 <test_array_set_overwrites_old_values+0xc2>
mov    %rbx,%rdi
call   1050 <sparse_array_free@plt>
mov    $0x1,%ebp
test   %eax,%eax
jne    1225 <test_array_set_overwrites_old_values+0xd5>
lea    0xe29(%rip),%rdi
mov    $0xa3,%esi
jmp    121e <test_array_set_overwrites_old_values+0xce>
lea    0xe1b(%rip),%rdi
mov    $0x9c,%esi
jmp    121e <test_array_set_overwrites_old_values+0xce>
lea    0xe0d(%rip),%rdi
mov    $0x9e,%esi
call   1040 <printf@plt>
jmp    1225 <test_array_set_overwrites_old_values+0xd5>
lea    0xdfa(%rip),%rdi
mov    $0x9f,%esi
call   1040 <printf@plt>
jmp    1225 <test_array_set_overwrites_old_values+0xd5>
lea    0xde7(%rip),%rdi
mov    $0xa1,%esi
call   1040 <printf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sparse_array = type { i32 }
@.str = [5 x i8] c"%i: \00"
define i32 @test_array_set_overwrites_old_values() {
%1 = alloca i32
%2 = alloca %struct.sparse_array*
%3 = alloca i32
%4 = alloca i32
store %struct.sparse_array* null, %struct.sparse_array** %2
store i32 666, i32* %3
store i32 1024, i32* %4
%5 = call %struct.sparse_array* @sparse_array_init(i32 4, i32 150)
store %struct.sparse_array* %5, %struct.sparse_array** %2
%6 = load %struct.sparse_array*, %struct.sparse_array** %2
%7 = icmp ne %struct.sparse_array* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 156)
store i32 0, i32* %1
br label %37
10: ; preds = %0
%11 = load %struct.sparse_array*, %struct.sparse_array** %2
%12 = call i32 @sparse_array_set(%struct.sparse_array* %11, i32 0, i32* %3, i32 4)
%13 = icmp ne i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 158)
store i32 0, i32* %1
br label %37
16: ; preds = %10
%17 = load %struct.sparse_array*, %struct.sparse_array** %2
%18 = call i32 @sparse_array_set(%struct.sparse_array* %17, i32 0, i32* %4, i32 4)
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 159)
store i32 0, i32* %1
br label %37
22: ; preds = %16
%23 = load %struct.sparse_array*, %struct.sparse_array** %2
%24 = call i64 @sparse_array_get(%struct.sparse_array* %23, i32 0, i32* null)
%25 = inttoptr i64 %24 to i32*
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 1024
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 161)
store i32 0, i32* %1
br label %37
30: ; preds = %22
%31 = load %struct.sparse_array*, %struct.sparse_array** %2
%32 = call i32 @sparse_array_free(%struct.sparse_array* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 163)
store i32 0, i32* %1
br label %37
36: ; preds = %30
store i32 1, i32* %1
br label %37
37: ; preds = %36, %34, %28, %20, %14, %8
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
%struct.sparse_array = type { i32 }
@.str = [5 x i8] c"%i: \00"
define i32 @test_array_set_overwrites_old_values() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 666, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 1024, i32* %2
%5 = tail call %struct.sparse_array* @sparse_array_init(i32 4, i32 150)
%6 = icmp eq %struct.sparse_array* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 156)
br label %31
9: ; preds = %0
%10 = call i32 @sparse_array_set(%struct.sparse_array* %5, i32 0, i32* %1, i32 4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 158)
br label %31
14: ; preds = %9
%15 = call i32 @sparse_array_set(%struct.sparse_array* %5, i32 0, i32* %2, i32 4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 159)
br label %31
19: ; preds = %14
%20 = call i64 @sparse_array_get(%struct.sparse_array* %5, i32 0, i32* null)
%21 = inttoptr i64 %20 to i32*
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 1024
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 161)
br label %31
26: ; preds = %19
%27 = call i32 @sparse_array_free(%struct.sparse_array* %5)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 163)
br label %31
31: ; preds = %26, %29, %24, %17, %12, %7
%32 = phi i32 [ 0, %29 ], [ 0, %24 ], [ 0, %17 ], [ 0, %12 ], [ 0, %7 ], [ 1, %26 ]
ret i32 %32
}