#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 uint8_t;

/* Variables and functions */
int bufToInt32(int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int insertInt16(int **, int *, int, int);
int /*<<< orphan*/ int32ToBuf(int, int *);
int /*<<< orphan*/ printf(char *, int);
int addInt16ToList(uint8_t **pnt, uint8_t *end, int length, int value) {
  int type = **pnt;
  if (type != 2) {
    printf("Attempting to add int32 to list not containing int16's (type is: "
           "%d)\n",
           type);
    exit(0);
  }
  *pnt += 1;
  int oldLen = bufToInt32(*pnt);
  int32ToBuf(oldLen + 1, *pnt);
  *pnt += 4;
  return insertInt16(pnt, end, length, value);
}


x86 assembly (clang, -O0):
<addInt16ToList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
je     1192 <addInt16ToList+0x42>
mov    -0x1c(%rbp),%esi
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x4,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <bufToInt32@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1070 <int32ToBuf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x10,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1050 <insertInt16@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addInt16ToList>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    (%rdi),%rdi
mov    (%rdi),%esi
cmp    $0x2,%esi
jne    11a6 <addInt16ToList+0x56>
mov    %ecx,%r14d
mov    %edx,%r15d
add    $0x4,%rdi
mov    %rdi,0x0(%rbp)
call   1040 <bufToInt32@plt>
lea    0x1(%rax),%edi
mov    0x0(%rbp),%rsi
call   1070 <int32ToBuf@plt>
addq   $0x10,0x0(%rbp)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <insertInt16@plt>
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [70 x i8] c"Attempting to add int32 to list not containing int16's (type is: %d)\0A\00"
define i32 @addInt16ToList(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
store i32** %0, i32*** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32**, i32*** %5
%12 = load i32*, i32** %11
%13 = load i32, i32* %12
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32, i32* %9
%18 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %4
%21 = load i32**, i32*** %5
%22 = load i32*, i32** %21
%23 = getelementptr inbounds i32, i32* %22, i64 1
store i32* %23, i32** %21
%24 = load i32**, i32*** %5
%25 = load i32*, i32** %24
%26 = call i32 @bufToInt32(i32* %25)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
%29 = load i32**, i32*** %5
%30 = load i32*, i32** %29
%31 = call i32 @int32ToBuf(i32 %28, i32* %30)
%32 = load i32**, i32*** %5
%33 = load i32*, i32** %32
%34 = getelementptr inbounds i32, i32* %33, i64 4
store i32* %34, i32** %32
%35 = load i32**, i32*** %5
%36 = load i32*, i32** %6
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = call i32 @insertInt16(i32** %35, i32* %36, i32 %37, i32 %38)
ret i32 %39
}

LLVM IR (-O2):
@.str = [70 x i8] c"Attempting to add int32 to list not containing int16's (type is: %d)\0A\00"
define i32 @addInt16ToList(i32** %0, i32* %1, i32 %2, i32 %3) {
%5 = load i32*, i32** %0
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 2
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %6)
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %4
%12 = getelementptr inbounds i32, i32* %5, i64 1
store i32* %12, i32** %0
%13 = tail call i32 @bufToInt32(i32* %12)
%14 = add nsw i32 %13, 1
%15 = load i32*, i32** %0
%16 = tail call i32 @int32ToBuf(i32 %14, i32* %15)
%17 = load i32*, i32** %0
%18 = getelementptr inbounds i32, i32* %17, i64 4
store i32* %18, i32** %0
%19 = tail call i32 @insertInt16(i32** %0, i32* %1, i32 %2, i32 %3)
ret i32 %19
}