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

/* Variables and functions */
int /*<<< orphan*/ ts_sdt_add_service_descriptor(struct ts_sdt *, int, int,
                                                 char *, char *);
struct ts_sdt *ts_sdt_alloc_init(int, int);
int /*<<< orphan*/ ts_sdt_dump(struct ts_sdt *);
int /*<<< orphan*/ ts_sdt_free(struct ts_sdt **);
int ts_sdt_test(void) {
  struct ts_sdt *sdt = ts_sdt_alloc_init(1, 2);
  ts_sdt_add_service_descriptor(sdt, 1007, 1, "BULSATCOM", "bTV");
  ts_sdt_dump(sdt);
  int i;
  for (i = 0; i < 25; i++) {
    ts_sdt_add_service_descriptor(sdt, 9, 0, "PROVIDER",
                                  "SERVICE3333333333333333333333333333333333333"
                                  "3333333333333333333333333");
    ts_sdt_add_service_descriptor(
        sdt, 13, 0,
        "PROddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
        "dddddddddddddVIDER",
        "SERVICE");
    ts_sdt_add_service_descriptor(sdt, 7, 0, "PROVIDER", "SERVICE");
  }
  ts_sdt_dump(sdt);
  ts_sdt_free(&sdt);
  return 0;
}


x86 assembly (clang, -O0):
<ts_sdt_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <ts_sdt_alloc_init@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3ef,%esi
mov    $0x1,%edx
lea    0xe90(%rip),%rcx
lea    0xe93(%rip),%r8
call   1040 <ts_sdt_add_service_descriptor@plt>
mov    -0x8(%rbp),%rdi
call   1050 <ts_sdt_dump@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x19,-0xc(%rbp)
jge    11fe <ts_sdt_test+0xbe>
mov    -0x8(%rbp),%rdi
mov    $0x9,%esi
xor    %edx,%edx
lea    0xe66(%rip),%rcx
lea    0xe68(%rip),%r8
call   1040 <ts_sdt_add_service_descriptor@plt>
mov    -0x8(%rbp),%rdi
mov    $0xd,%esi
xor    %edx,%edx
lea    0xe97(%rip),%rcx
lea    0xee9(%rip),%r8
call   1040 <ts_sdt_add_service_descriptor@plt>
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
xor    %edx,%edx
lea    0xe2a(%rip),%rcx
lea    0xecb(%rip),%r8
call   1040 <ts_sdt_add_service_descriptor@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118c <ts_sdt_test+0x4c>
mov    -0x8(%rbp),%rdi
call   1050 <ts_sdt_dump@plt>
lea    -0x8(%rbp),%rdi
call   1060 <ts_sdt_free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_sdt_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <ts_sdt_alloc_init@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
lea    0xe98(%rip),%rcx
lea    0xe9b(%rip),%r8
mov    %rax,%rdi
mov    $0x3ef,%esi
mov    $0x1,%edx
call   1040 <ts_sdt_add_service_descriptor@plt>
mov    %rbx,%rdi
call   1050 <ts_sdt_dump@plt>
mov    $0x19,%ebp
lea    0xe79(%rip),%r14
lea    0xe7b(%rip),%r15
lea    0xeba(%rip),%r12
lea    0xf0c(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    %r15,%r8
call   1040 <ts_sdt_add_service_descriptor@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
xor    %edx,%edx
mov    %r12,%rcx
mov    %r13,%r8
call   1040 <ts_sdt_add_service_descriptor@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %edx,%edx
mov    %r14,%rcx
mov    %r13,%r8
call   1040 <ts_sdt_add_service_descriptor@plt>
add    $0xffffffff,%ebp
jne    11b0 <ts_sdt_test+0x70>
mov    %rbx,%rdi
call   1050 <ts_sdt_dump@plt>
mov    %rsp,%rdi
call   1060 <ts_sdt_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ts_sdt = type { i32 }
@.str = [10 x i8] c"BULSATCOM\00"
@.str.1 = [4 x i8] c"bTV\00"
@.str.2 = [9 x i8] c"PROVIDER\00"
@.str.3 = [70 x i8] c"SERVICE33333333333333333333333333333333333333333333333333333333333333\00"
@.str.4 = [89 x i8] c"PROddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddVIDER\00"
@.str.5 = [8 x i8] c"SERVICE\00"
define i32 @ts_sdt_test() {
%1 = alloca %struct.ts_sdt*
%2 = alloca i32
%3 = call %struct.ts_sdt* @ts_sdt_alloc_init(i32 1, i32 2)
store %struct.ts_sdt* %3, %struct.ts_sdt** %1
%4 = load %struct.ts_sdt*, %struct.ts_sdt** %1
%5 = call i32 @ts_sdt_add_service_descriptor(%struct.ts_sdt* %4, i32 1007, i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%6 = load %struct.ts_sdt*, %struct.ts_sdt** %1
%7 = call i32 @ts_sdt_dump(%struct.ts_sdt* %6)
store i32 0, i32* %2
br label %8
8: ; preds = %18, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 25
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load %struct.ts_sdt*, %struct.ts_sdt** %1
%13 = call i32 @ts_sdt_add_service_descriptor(%struct.ts_sdt* %12, i32 9, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
%14 = load %struct.ts_sdt*, %struct.ts_sdt** %1
%15 = call i32 @ts_sdt_add_service_descriptor(%struct.ts_sdt* %14, i32 13, i32 0, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%16 = load %struct.ts_sdt*, %struct.ts_sdt** %1
%17 = call i32 @ts_sdt_add_service_descriptor(%struct.ts_sdt* %16, i32 7, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %18
18: ; preds = %11
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %8
21: ; preds = %8
%22 = load %struct.ts_sdt*, %struct.ts_sdt** %1
%23 = call i32 @ts_sdt_dump(%struct.ts_sdt* %22)
%24 = call i32 @ts_sdt_free(%struct.ts_sdt** %1)
ret i32 0
}

LLVM IR (-O2):
%struct.ts_sdt = type { i32 }
@.str = [10 x i8] c"BULSATCOM\00"
@.str.1 = [4 x i8] c"bTV\00"
@.str.2 = [9 x i8] c"PROVIDER\00"
@.str.3 = [70 x i8] c"SERVICE33333333333333333333333333333333333333333333333333333333333333\00"
@.str.4 = [89 x i8] c"PROddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddVIDER\00"
@.str.5 = [8 x i8] c"SERVICE\00"
define i32 @ts_sdt_test() {
%1 = alloca %struct.ts_sdt*
%2 = bitcast %struct.ts_sdt** %1 to i8*
%3 = tail call %struct.ts_sdt* @ts_sdt_alloc_init(i32 1, i32 2)
store %struct.ts_sdt* %3, %struct.ts_sdt** %1
%4 = tail call i32 @ts_sdt_add_service_descriptor(%struct.ts_sdt* %3, i32 1007, i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @ts_sdt_dump(%struct.ts_sdt* %3)
br label %6
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %11, %6 ]
%8 = tail call i32 @ts_sdt_add_service_descriptor(%struct.ts_sdt* %3, i32 9, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 @ts_sdt_add_service_descriptor(%struct.ts_sdt* %3, i32 13, i32 0, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%10 = tail call i32 @ts_sdt_add_service_descriptor(%struct.ts_sdt* %3, i32 7, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%11 = add nuw nsw i32 %7, 1
%12 = icmp eq i32 %11, 25
br i1 %12, label %13, label %6
13: ; preds = %6
%14 = tail call i32 @ts_sdt_dump(%struct.ts_sdt* %3)
%15 = call i32 @ts_sdt_free(%struct.ts_sdt** %1)
ret i32 0
}