#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 ts_pat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ts_pat_add_program(struct ts_pat *, int, int);
struct ts_pat *ts_pat_alloc_init(int);
int /*<<< orphan*/ ts_pat_del_program(struct ts_pat *, int);
int /*<<< orphan*/ ts_pat_dump(struct ts_pat *);
int /*<<< orphan*/ ts_pat_free(struct ts_pat **);
void ts_pat_test(void) {
  struct ts_pat *pat = ts_pat_alloc_init(0x7878);
  ts_pat_dump(pat);
  ts_pat_add_program(pat, 1, 0x100);
  ts_pat_add_program(pat, 2, 0x100);
  ts_pat_add_program(pat, 3, 0x100);
  ts_pat_dump(pat);
  ts_pat_del_program(pat, 2);
  ts_pat_dump(pat);
  ts_pat_del_program(pat, 3);
  ts_pat_dump(pat);
  int i;
  for (i = 0; i < 10; i++) {
    ts_pat_add_program(pat, i + 10, (i + 5) * 10);
  }
  ts_pat_dump(pat);
  ts_pat_free(&pat);
}


x86 assembly (clang, -O0):
<ts_pat_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x7878,%edi
call   1030 <ts_pat_alloc_init@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <ts_pat_dump@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x100,%edx
call   1070 <ts_pat_add_program@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
mov    $0x100,%edx
call   1070 <ts_pat_add_program@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3,%esi
mov    $0x100,%edx
call   1070 <ts_pat_add_program@plt>
mov    -0x8(%rbp),%rdi
call   1050 <ts_pat_dump@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
call   1060 <ts_pat_del_program@plt>
mov    -0x8(%rbp),%rdi
call   1050 <ts_pat_dump@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3,%esi
call   1060 <ts_pat_del_program@plt>
mov    -0x8(%rbp),%rdi
call   1050 <ts_pat_dump@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1216 <ts_pat_test+0xc6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0xa,%esi
mov    -0xc(%rbp),%eax
add    $0x5,%eax
imul   $0xa,%eax,%edx
call   1070 <ts_pat_add_program@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e6 <ts_pat_test+0x96>
mov    -0x8(%rbp),%rdi
call   1050 <ts_pat_dump@plt>
lea    -0x8(%rbp),%rdi
call   1040 <ts_pat_free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_pat_test>:
push   %rbx
sub    $0x10,%rsp
mov    $0x7878,%edi
call   1030 <ts_pat_alloc_init@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   1050 <ts_pat_dump@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x100,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x100,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
call   1050 <ts_pat_dump@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <ts_pat_del_program@plt>
mov    %rbx,%rdi
call   1050 <ts_pat_dump@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1060 <ts_pat_del_program@plt>
mov    %rbx,%rdi
call   1050 <ts_pat_dump@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x32,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
mov    $0x3c,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
mov    $0x46,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
mov    $0x50,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0xe,%esi
mov    $0x5a,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0xf,%esi
mov    $0x64,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    $0x6e,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0x11,%esi
mov    $0x78,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0x12,%esi
mov    $0x82,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
mov    $0x13,%esi
mov    $0x8c,%edx
call   1070 <ts_pat_add_program@plt>
mov    %rbx,%rdi
call   1050 <ts_pat_dump@plt>
lea    0x8(%rsp),%rdi
call   1040 <ts_pat_free@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.ts_pat = type { i32 }
define void @ts_pat_test() {
%1 = alloca %struct.ts_pat*
%2 = alloca i32
%3 = call %struct.ts_pat* @ts_pat_alloc_init(i32 30840)
store %struct.ts_pat* %3, %struct.ts_pat** %1
%4 = load %struct.ts_pat*, %struct.ts_pat** %1
%5 = call i32 @ts_pat_dump(%struct.ts_pat* %4)
%6 = load %struct.ts_pat*, %struct.ts_pat** %1
%7 = call i32 @ts_pat_add_program(%struct.ts_pat* %6, i32 1, i32 256)
%8 = load %struct.ts_pat*, %struct.ts_pat** %1
%9 = call i32 @ts_pat_add_program(%struct.ts_pat* %8, i32 2, i32 256)
%10 = load %struct.ts_pat*, %struct.ts_pat** %1
%11 = call i32 @ts_pat_add_program(%struct.ts_pat* %10, i32 3, i32 256)
%12 = load %struct.ts_pat*, %struct.ts_pat** %1
%13 = call i32 @ts_pat_dump(%struct.ts_pat* %12)
%14 = load %struct.ts_pat*, %struct.ts_pat** %1
%15 = call i32 @ts_pat_del_program(%struct.ts_pat* %14, i32 2)
%16 = load %struct.ts_pat*, %struct.ts_pat** %1
%17 = call i32 @ts_pat_dump(%struct.ts_pat* %16)
%18 = load %struct.ts_pat*, %struct.ts_pat** %1
%19 = call i32 @ts_pat_del_program(%struct.ts_pat* %18, i32 3)
%20 = load %struct.ts_pat*, %struct.ts_pat** %1
%21 = call i32 @ts_pat_dump(%struct.ts_pat* %20)
store i32 0, i32* %2
br label %22
22: ; preds = %33, %0
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 10
br i1 %24, label %25, label %36
25: ; preds = %22
%26 = load %struct.ts_pat*, %struct.ts_pat** %1
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 10
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 5
%31 = mul nsw i32 %30, 10
%32 = call i32 @ts_pat_add_program(%struct.ts_pat* %26, i32 %28, i32 %31)
br label %33
33: ; preds = %25
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %22
36: ; preds = %22
%37 = load %struct.ts_pat*, %struct.ts_pat** %1
%38 = call i32 @ts_pat_dump(%struct.ts_pat* %37)
%39 = call i32 @ts_pat_free(%struct.ts_pat** %1)
ret void
}

LLVM IR (-O2):
%struct.ts_pat = type { i32 }
define void @ts_pat_test() {
%1 = alloca %struct.ts_pat*
%2 = bitcast %struct.ts_pat** %1 to i8*
%3 = tail call %struct.ts_pat* @ts_pat_alloc_init(i32 30840)
store %struct.ts_pat* %3, %struct.ts_pat** %1
%4 = tail call i32 @ts_pat_dump(%struct.ts_pat* %3)
%5 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 1, i32 256)
%6 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 2, i32 256)
%7 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 3, i32 256)
%8 = tail call i32 @ts_pat_dump(%struct.ts_pat* %3)
%9 = tail call i32 @ts_pat_del_program(%struct.ts_pat* %3, i32 2)
%10 = tail call i32 @ts_pat_dump(%struct.ts_pat* %3)
%11 = tail call i32 @ts_pat_del_program(%struct.ts_pat* %3, i32 3)
%12 = tail call i32 @ts_pat_dump(%struct.ts_pat* %3)
%13 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 10, i32 50)
%14 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 11, i32 60)
%15 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 12, i32 70)
%16 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 13, i32 80)
%17 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 14, i32 90)
%18 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 15, i32 100)
%19 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 16, i32 110)
%20 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 17, i32 120)
%21 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 18, i32 130)
%22 = tail call i32 @ts_pat_add_program(%struct.ts_pat* %3, i32 19, i32 140)
%23 = tail call i32 @ts_pat_dump(%struct.ts_pat* %3)
%24 = call i32 @ts_pat_free(%struct.ts_pat** %1)
ret void
}