#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*/ ck_assert_failed(char *, int, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t const);
void *realloc(void *, size_t const);
void *vector_realloc(void *data, size_t elem_size, size_t size, size_t used) {
  const size_t total_size = elem_size * size;
  const size_t used_size = elem_size * used;
  do {
    if (!(size <= (~(size_t)0u) / elem_size))
      ck_assert_failed("/scratch/repos/new/home/jordi_armengol_estape/"
                       "c-scraper/outputs/2022-01-22/02-19-57/repos/gstrauss/"
                       "lighttpd1.4/refs/heads/master/src/vector.c",
                       15, "size <= (~(size_t)0u) / elem_size");
  } while (0);
  data = realloc(data, total_size);
  do {
    if (!(NULL != data))
      ck_assert_failed("/scratch/repos/new/home/jordi_armengol_estape/"
                       "c-scraper/outputs/2022-01-22/02-19-57/repos/gstrauss/"
                       "lighttpd1.4/refs/heads/master/src/vector.c",
                       17, "NULL != data");
  } while (0);
  memset(((char *)data) + used_size, 0, total_size - used_size);
  return data;
}


x86 assembly (clang, -O0):
<vector_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0xffffffffffffffff,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jbe    11a1 <vector_realloc+0x71>
lea    0xe70(%rip),%rdi
mov    $0xf,%esi
lea    0xef2(%rip),%rdx
call   1040 <ck_assert_failed@plt>
jmp    11a6 <vector_realloc+0x76>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    11db <vector_realloc+0xab>
lea    0xe36(%rip),%rdi
mov    $0x11,%esi
lea    0xeda(%rip),%rdx
call   1040 <ck_assert_failed@plt>
jmp    11e0 <vector_realloc+0xb0>
mov    -0x8(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
sub    -0x30(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_realloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rdx,%rbx
imul   %rsi,%rbx
mov    %rsi,%rax
mul    %rdx
jno    1168 <vector_realloc+0x38>
lea    0xea9(%rip),%rdi
lea    0xf30(%rip),%rdx
mov    $0xf,%esi
call   1040 <ck_assert_failed@plt>
imul   %r12,%r14
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1197 <vector_realloc+0x67>
lea    0xe7a(%rip),%rdi
lea    0xf23(%rip),%rdx
mov    $0x11,%esi
call   1040 <ck_assert_failed@plt>
mov    %r15,%rdi
add    %r14,%rdi
sub    %r14,%rbx
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gstrauss/lighttpd1.4/refs/heads/master/src/vector.c\00"
@.str.1 = [34 x i8] c"size <= (~(size_t)0u) / elem_size\00"
@.str.2 = [13 x i8] c"NULL != data\00"
define i8* @vector_realloc(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i64, i64* %6
%12 = load i64, i64* %7
%13 = mul i64 %11, %12
store i64 %13, i64* %9
%14 = load i64, i64* %6
%15 = load i64, i64* %8
%16 = mul i64 %14, %15
store i64 %16, i64* %10
br label %17
17: ; preds = %4
%18 = load i64, i64* %7
%19 = load i64, i64* %6
%20 = udiv i64 -1, %19
%21 = icmp ule i64 %18, %20
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = call i32 @ck_assert_failed(i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str, i64 0, i64 0), i32 15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
br label %25
25: ; preds = %24
%26 = load i8*, i8** %5
%27 = load i64, i64* %9
%28 = call i8* @realloc(i8* %26, i64 %27)
store i8* %28, i8** %5
br label %29
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = icmp ne i8* null, %30
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @ck_assert_failed(i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str, i64 0, i64 0), i32 17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
br label %35
35: ; preds = %34
%36 = load i8*, i8** %5
%37 = load i64, i64* %10
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = load i64, i64* %9
%40 = load i64, i64* %10
%41 = sub i64 %39, %40
%42 = call i32 @memset(i8* %38, i32 0, i64 %41)
%43 = load i8*, i8** %5
ret i8* %43
}

LLVM IR (-O2):
@.str = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gstrauss/lighttpd1.4/refs/heads/master/src/vector.c\00"
@.str.1 = [34 x i8] c"size <= (~(size_t)0u) / elem_size\00"
@.str.2 = [13 x i8] c"NULL != data\00"
define i8* @vector_realloc(i8* nocapture %0, i64 %1, i64 %2, i64 %3) {
%5 = mul i64 %2, %1
%6 = mul i64 %3, %1
%7 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %1, i64 %2)
%8 = extractvalue { i64, i1 } %7, 1
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @ck_assert_failed(i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str, i64 0, i64 0), i32 15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = tail call i8* @realloc(i8* %0, i64 %5)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @ck_assert_failed(i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str, i64 0, i64 0), i32 17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = getelementptr inbounds i8, i8* %12, i64 %6
%18 = sub i64 %5, %6
%19 = tail call i32 @memset(i8* %17, i32 0, i64 %18)
ret i8* %12
}