#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 /*<<< orphan*/ printf(char *, int const, ...);
void parse_ttx(const uint8_t *ttx, size_t size) {
  do {
    printf("TTX : "
           "Got teletext packet of size %zu\n",
           size);
  } while (0);
  if (ttx[0] < 0x10 || ttx[0] > 0x1F) {
    do {
      printf("TTX : "
             "Data identifier 0x%hhx is not EBU Teletext.\n",
             ttx[0]);
    } while (0);
    return;
  }
  const unsigned int data_unit_num = (size - 1) / 46;
  for (unsigned int i = 0; i < data_unit_num; ++i) {
    const uint8_t *ttx_data_unit = ttx + 1 + (i * 46);
    do {
      printf("TTX : "
             "data_unit_id = 0x%hhx, field_parity = %u, line_offset = %u"
             ", framing_code = 0x%hhx, magazine_and_packet_address = 0x%hhx%hhx"
             "\n",
             ttx_data_unit[0], ttx_data_unit[2] & 0x20, ttx_data_unit[2] & 0x1f,
             ttx_data_unit[3], ttx_data_unit[4], ttx_data_unit[5]);
    } while (0);
  }
}


x86 assembly (clang, -O0):
<parse_ttx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
cmpl   $0x10,(%rax)
jl     114e <parse_ttx+0x3e>
mov    -0x8(%rbp),%rax
cmpl   $0x1f,(%rax)
jle    116c <parse_ttx+0x5c>
jmp    1153 <parse_ttx+0x43>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1202 <parse_ttx+0xf2>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    $0x2e,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1202 <parse_ttx+0xf2>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
imul   $0x2e,-0x18(%rbp),%ecx
mov    %ecx,%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edx
and    $0x20,%edx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%ecx
and    $0x1f,%ecx
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r9d
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xe75(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f4 <parse_ttx+0xe4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1188 <parse_ttx+0x78>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ttx>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xedb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r12),%esi
lea    -0x20(%rsi),%eax
cmp    $0xffffffef,%eax
ja     1151 <parse_ttx+0x41>
lea    0xee8(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <printf@plt>
add    $0xffffffffffffffff,%r14
shr    %r14
movabs $0xb21642c8590b2165,%rcx
42 16 b2
mov    %r14,%rax
mul    %rcx
shr    $0x4,%rdx
test   %edx,%edx
je     11bc <parse_ttx+0xac>
mov    %edx,%eax
imul   $0x2e,%rax,%r15
lea    0xedd(%rip),%r14
xor    %ebx,%ebx
nop
mov    %ebx,%eax
and    $0xfffffffe,%eax
mov    0x4(%r12,%rax,4),%esi
mov    0xc(%r12,%rax,4),%ecx
mov    %ecx,%edx
and    $0x20,%edx
and    $0x1f,%ecx
mov    0x10(%r12,%rax,4),%r8d
mov    0x14(%r12,%rax,4),%r9d
mov    0x18(%r12,%rax,4),%eax
mov    %eax,(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x2e,%rbx
cmp    %rbx,%r15
jne    1180 <parse_ttx+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [39 x i8] c"TTX : Got teletext packet of size %zu\0A\00"
@.str.1 = [51 x i8] c"TTX : Data identifier 0x%hhx is not EBU Teletext.\0A\00"
@.str.2 = [131 x i8] c"TTX : data_unit_id = 0x%hhx, field_parity = %u, line_offset = %u, framing_code = 0x%hhx, magazine_and_packet_address = 0x%hhx%hhx\0A\00"
define void @parse_ttx(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32* %0, i32** %3
store i64 %1, i64* %4
br label %8
8: ; preds = %2
%9 = load i64, i64* %4
%10 = trunc i64 %9 to i32
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i64 0
%15 = load i32, i32* %14
%16 = icmp slt i32 %15, 16
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = icmp sgt i32 %20, 31
br i1 %21, label %22, label %29
22: ; preds = %17, %12
br label %23
23: ; preds = %22
%24 = load i32*, i32** %3
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = load i32, i32* %25
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %23
br label %71
29: ; preds = %17
%30 = load i64, i64* %4
%31 = sub i64 %30, 1
%32 = udiv i64 %31, 46
%33 = trunc i64 %32 to i32
store i32 %33, i32* %5
store i32 0, i32* %6
br label %34
34: ; preds = %68, %29
%35 = load i32, i32* %6
%36 = load i32, i32* %5
%37 = icmp ult i32 %35, %36
br i1 %37, label %38, label %71
38: ; preds = %34
%39 = load i32*, i32** %3
%40 = getelementptr inbounds i32, i32* %39, i64 1
%41 = load i32, i32* %6
%42 = mul i32 %41, 46
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %40, i64 %43
store i32* %44, i32** %7
br label %45
45: ; preds = %38
%46 = load i32*, i32** %7
%47 = getelementptr inbounds i32, i32* %46, i64 0
%48 = load i32, i32* %47
%49 = load i32*, i32** %7
%50 = getelementptr inbounds i32, i32* %49, i64 2
%51 = load i32, i32* %50
%52 = and i32 %51, 32
%53 = load i32*, i32** %7
%54 = getelementptr inbounds i32, i32* %53, i64 2
%55 = load i32, i32* %54
%56 = and i32 %55, 31
%57 = load i32*, i32** %7
%58 = getelementptr inbounds i32, i32* %57, i64 3
%59 = load i32, i32* %58
%60 = load i32*, i32** %7
%61 = getelementptr inbounds i32, i32* %60, i64 4
%62 = load i32, i32* %61
%63 = load i32*, i32** %7
%64 = getelementptr inbounds i32, i32* %63, i64 5
%65 = load i32, i32* %64
%66 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %52, i32 %56, i32 %59, i32 %62, i32 %65)
br label %67
67: ; preds = %45
br label %68
68: ; preds = %67
%69 = load i32, i32* %6
%70 = add i32 %69, 1
store i32 %70, i32* %6
br label %34
71: ; preds = %28, %34
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"TTX : Got teletext packet of size %zu\0A\00"
@.str.1 = [51 x i8] c"TTX : Data identifier 0x%hhx is not EBU Teletext.\0A\00"
@.str.2 = [131 x i8] c"TTX : data_unit_id = 0x%hhx, field_parity = %u, line_offset = %u, framing_code = 0x%hhx, magazine_and_packet_address = 0x%hhx%hhx\0A\00"
define void @parse_ttx(i32* nocapture %0, i64 %1) {
%3 = trunc i64 %1 to i32
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* %0
%6 = add i32 %5, -32
%7 = icmp ult i32 %6, -16
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %37
10: ; preds = %2
%11 = add i64 %1, -1
%12 = udiv i64 %11, 46
%13 = trunc i64 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %37, label %15
15: ; preds = %10
%16 = getelementptr inbounds i32, i32* %0, i64 1
%17 = and i64 %12, 4294967295
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ 0, %15 ], [ %35, %18 ]
%20 = mul i64 %19, 46
%21 = and i64 %20, 4294967294
%22 = getelementptr inbounds i32, i32* %16, i64 %21
%23 = load i32, i32* %22
%24 = getelementptr inbounds i32, i32* %22, i64 2
%25 = load i32, i32* %24
%26 = and i32 %25, 32
%27 = and i32 %25, 31
%28 = getelementptr inbounds i32, i32* %22, i64 3
%29 = load i32, i32* %28
%30 = getelementptr inbounds i32, i32* %22, i64 4
%31 = load i32, i32* %30
%32 = getelementptr inbounds i32, i32* %22, i64 5
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %26, i32 %27, i32 %29, i32 %31, i32 %33)
%35 = add nuw nsw i64 %19, 1
%36 = icmp eq i64 %35, %17
br i1 %36, label %37, label %18
37: ; preds = %18, %10, %8
ret void
}