#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*/ memset(int *, int /*<<< orphan*/, int);
int *realloc(int *, int);
int *change_pattern_length(int *old_pattern, int num_tracks, int old_length,
                           int new_length) {
  int old_sz = num_tracks * old_length;
  int new_sz = num_tracks * new_length;
  int *new_pattern = realloc(old_pattern, sizeof(int) * new_sz);
  if (new_pattern == NULL) {
  }
  if (new_length > old_length) {
    memset(new_pattern + old_sz, 0, sizeof(int) * (new_sz - old_sz));
  }
  return new_pattern;
}


x86 assembly (clang, -O0):
<change_pattern_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1170 <change_pattern_length+0x50>
jmp    1170 <change_pattern_length+0x50>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11a0 <change_pattern_length+0x80>
mov    -0x28(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x1c(%rbp),%eax
sub    -0x18(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_pattern_length>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %esi,%r15d
mov    %ecx,%ebx
imul   %esi,%ebx
lea    0x0(,%rbx,4),%esi
call   1040 <realloc@plt>
mov    %rax,%r14
cmp    %ebp,%r12d
jle    1162 <change_pattern_length+0x42>
imul   %r15d,%ebp
movslq %ebp,%rax
lea    (%r14,%rax,4),%rdi
sub    %eax,%ebx
shl    $0x2,%ebx
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <memset@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @change_pattern_length(i32* %0, i32 %1, i32 %2, i32 %3) {
%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
store i32 %3, i32* %8
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = mul nsw i32 %12, %13
store i32 %14, i32* %9
%15 = load i32, i32* %6
%16 = load i32, i32* %8
%17 = mul nsw i32 %15, %16
store i32 %17, i32* %10
%18 = load i32*, i32** %5
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = mul i64 4, %20
%22 = trunc i64 %21 to i32
%23 = call i32* @realloc(i32* %18, i32 %22)
store i32* %23, i32** %11
%24 = load i32*, i32** %11
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %4
br label %27
27: ; preds = %26, %4
%28 = load i32, i32* %8
%29 = load i32, i32* %7
%30 = icmp sgt i32 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i32*, i32** %11
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %10
%37 = load i32, i32* %9
%38 = sub nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = mul i64 4, %39
%41 = trunc i64 %40 to i32
%42 = call i32 @memset(i32* %35, i32 0, i32 %41)
br label %43
43: ; preds = %31, %27
%44 = load i32*, i32** %11
ret i32* %44
}

LLVM IR (-O2):
define i32* @change_pattern_length(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %2, %1
%6 = mul nsw i32 %3, %1
%7 = shl i32 %6, 2
%8 = tail call i32* @realloc(i32* %0, i32 %7)
%9 = icmp sgt i32 %3, %2
br i1 %9, label %10, label %16
10: ; preds = %4
%11 = sext i32 %5 to i64
%12 = getelementptr inbounds i32, i32* %8, i64 %11
%13 = sub nsw i32 %6, %5
%14 = shl i32 %13, 2
%15 = tail call i32 @memset(i32* %12, i32 0, i32 %14)
br label %16
16: ; preds = %10, %4
ret i32* %8
}