#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 */
struct sock_fprog {
  int len;
  struct sock_filter *filter;
};
struct sock_filter {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int ENOMEM;
struct sock_filter *realloc(struct sock_filter *, int);
int __add_inst(struct sock_fprog *fprog, struct sock_filter *inst) {
  ssize_t newsize;
  struct sock_filter *newfilter;
  newsize = sizeof(struct sock_filter) * (fprog->len + 1);
  newfilter = realloc(fprog->filter, newsize);
  if (!newfilter)
    return -ENOMEM;
  fprog->filter = newfilter;
  fprog->filter[fprog->len] = *inst;
  fprog->len += 1;
  return 0;
}


x86 assembly (clang, -O0):
<__add_inst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1164 <__add_inst+0x54>
xor    %eax,%eax
mov    0x2e86(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <__add_inst+0x8a>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    -0x18(%rbp),%rdx
mov    (%rdx),%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__add_inst>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%eax
lea    0x4(,%rax,4),%esi
mov    0x8(%rdi),%rdi
call   1030 <realloc@plt>
test   %rax,%rax
je     1145 <__add_inst+0x35>
mov    %rax,0x8(%rbx)
movslq (%rbx),%rcx
mov    (%r14),%edx
mov    %edx,(%rax,%rcx,4)
addl   $0x1,(%rbx)
xor    %eax,%eax
jmp    1150 <__add_inst+0x40>
mov    0x2e94(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sock_fprog = type { i32, %struct.sock_filter* }
%struct.sock_filter = type { i32 }
@ENOMEM = global i32 0
define i32 @__add_inst(%struct.sock_fprog* %0, %struct.sock_filter* %1) {
%3 = alloca i32
%4 = alloca %struct.sock_fprog*
%5 = alloca %struct.sock_filter*
%6 = alloca i32
%7 = alloca %struct.sock_filter*
store %struct.sock_fprog* %0, %struct.sock_fprog** %4
store %struct.sock_filter* %1, %struct.sock_filter** %5
%8 = load %struct.sock_fprog*, %struct.sock_fprog** %4
%9 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = mul i64 4, %12
%14 = trunc i64 %13 to i32
store i32 %14, i32* %6
%15 = load %struct.sock_fprog*, %struct.sock_fprog** %4
%16 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %15, i32 0, i32 1
%17 = load %struct.sock_filter*, %struct.sock_filter** %16
%18 = load i32, i32* %6
%19 = call %struct.sock_filter* @realloc(%struct.sock_filter* %17, i32 %18)
store %struct.sock_filter* %19, %struct.sock_filter** %7
%20 = load %struct.sock_filter*, %struct.sock_filter** %7
%21 = icmp ne %struct.sock_filter* %20, null
br i1 %21, label %25, label %22
22: ; preds = %2
%23 = load i32, i32* @ENOMEM
%24 = sub nsw i32 0, %23
store i32 %24, i32* %3
br label %44
25: ; preds = %2
%26 = load %struct.sock_filter*, %struct.sock_filter** %7
%27 = load %struct.sock_fprog*, %struct.sock_fprog** %4
%28 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %27, i32 0, i32 1
store %struct.sock_filter* %26, %struct.sock_filter** %28
%29 = load %struct.sock_fprog*, %struct.sock_fprog** %4
%30 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %29, i32 0, i32 1
%31 = load %struct.sock_filter*, %struct.sock_filter** %30
%32 = load %struct.sock_fprog*, %struct.sock_fprog** %4
%33 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %31, i64 %35
%37 = load %struct.sock_filter*, %struct.sock_filter** %5
%38 = bitcast %struct.sock_filter* %36 to i8*
%39 = bitcast %struct.sock_filter* %37 to i8*
%40 = load %struct.sock_fprog*, %struct.sock_fprog** %4
%41 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
store i32 %43, i32* %41
store i32 0, i32* %3
br label %44
44: ; preds = %25, %22
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
%struct.sock_fprog = type { i32, %struct.sock_filter* }
%struct.sock_filter = type { i32 }
@ENOMEM = global i32 0
define i32 @__add_inst(%struct.sock_fprog* nocapture %0, %struct.sock_filter* nocapture %1) {
%3 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = shl i32 %4, 2
%6 = add i32 %5, 4
%7 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %0, i64 0, i32 1
%8 = load %struct.sock_filter*, %struct.sock_filter** %7
%9 = tail call %struct.sock_filter* @realloc(%struct.sock_filter* %8, i32 %6)
%10 = icmp eq %struct.sock_filter* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @ENOMEM
%13 = sub nsw i32 0, %12
br label %22
14: ; preds = %2
store %struct.sock_filter* %9, %struct.sock_filter** %7
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr %struct.sock_filter, %struct.sock_filter* %1, i64 0, i32 0
%18 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %9, i64 %16, i32 0
%19 = load i32, i32* %17
store i32 %19, i32* %18
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %22
22: ; preds = %14, %11
%23 = phi i32 [ 0, %14 ], [ %13, %11 ]
ret i32 %23
}