#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;
typedef int uint32_t;
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ b_diff(int *, int, int *);
int dec_u4_be(int *, int /*<<< orphan*/ *);
int enc_u4_be(int *, int);
void ser_test(void) {
  uint32_t a[][6] = {
      {1, 1, 0xff, 0xff, 0xff, 0xff},
      {((1) << 7) | (1), 1 | 0x80, 1, 0xff, 0xff, 0xff},
      {((1) << (7 + 7)) | ((1) << 7) | (1), 1 | 0x80, 1 | 0x80, 1, 0xff, 0xff},
      {((1) << (7 + 7 + 7)) | ((1) << (7 + 7)) | ((1) << 7) | (1), 1 | 0x80,
       1 | 0x80, 1 | 0x80, 1, 0xff},
      {((1) << (7 + 7 + 7 + 7)) | ((1) << (7 + 7 + 7)) | ((1) << (7 + 7)) |
           ((1) << 7) | (1),
       1 | 0x80, 1 | 0x80, 1 | 0x80, 1 | 0x80, 1},
      {((1) << (7 + 7 + 7 + 7)) | ((2) << (7 + 7 + 7)) | ((3) << (7 + 7)) |
           ((4) << 7) | (5),
       1 | 0x80, 2 | 0x80, 3 | 0x80, 4 | 0x80, 5},
      {((5) << (7 + 7 + 7 + 7)) | ((4) << (7 + 7 + 7)) | ((3) << (7 + 7)) |
           ((2) << 7) | (1),
       5 | 0x80, 4 | 0x80, 3 | 0x80, 2 | 0x80, 1}};
  int i;
  int a_len = sizeof(a) / sizeof(a[0]);
  uint32_t x, y, *zp;
  uint8_t enc[5], *encp, enc2[5];
  int enc_len;
  for (i = 0; i < a_len; i++) {
    enc[0] = 0xff;
    enc[1] = 0xff;
    enc[2] = 0xff;
    enc[3] = 0xff;
    enc[4] = 0xff;
    encp = enc;
    zp = &a[i][1];
    x = a[i][0];
    enc_len = 0;
    while (x) {
      y = x & 0x7f;
      x = x >> 7;
      *encp++ = *zp++;
      enc_len++;
    }
    assert(a[i][0] == dec_u4_be(enc, NULL));
    assert(enc_len == enc_u4_be(enc2, a[i][0]));
    assert(enc_len == enc_u4_be(NULL, a[i][0]));
    assert(b_diff(enc, enc_len, enc2) == 0);
  }
}


x86 assembly (clang, -O0):
<ser_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0xb0(%rbp),%rdi
lea    0xe97(%rip),%rsi
mov    $0xa8,%edx
call   1050 <memcpy@plt>
movl   $0x7,-0xb8(%rbp)
movl   $0x0,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
cmp    -0xb8(%rbp),%eax
jge    1398 <ser_test+0x248>
movl   $0xff,-0xe0(%rbp)
movl   $0xff,-0xdc(%rbp)
movl   $0xff,-0xd8(%rbp)
movl   $0xff,-0xd4(%rbp)
movl   $0xff,-0xd0(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0xe8(%rbp)
movslq -0xb4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
add    $0x4,%rax
mov    %rax,-0xc8(%rbp)
movslq -0xb4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
movl   $0x0,-0x104(%rbp)
cmpl   $0x0,-0xbc(%rbp)
je     128d <ser_test+0x13d>
mov    -0xbc(%rbp),%eax
and    $0x7f,%eax
mov    %eax,-0xc0(%rbp)
mov    -0xbc(%rbp),%eax
sar    $0x7,%eax
mov    %eax,-0xbc(%rbp)
mov    -0xc8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0xc8(%rbp)
mov    (%rax),%ecx
mov    -0xe8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0xe8(%rbp)
mov    %ecx,(%rax)
mov    -0x104(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x104(%rbp)
jmp    1220 <ser_test+0xd0>
movslq -0xb4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x110(%rbp)
lea    -0xe0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <dec_u4_be@plt>
mov    %eax,%ecx
mov    -0x110(%rbp),%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x104(%rbp),%eax
mov    %eax,-0x10c(%rbp)
lea    -0x100(%rbp),%rdi
movslq -0xb4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%esi
call   1060 <enc_u4_be@plt>
mov    %eax,%ecx
mov    -0x10c(%rbp),%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x104(%rbp),%eax
mov    %eax,-0x108(%rbp)
movslq -0xb4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <enc_u4_be@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x104(%rbp),%esi
lea    -0x100(%rbp),%rdx
call   1030 <b_diff@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    1187 <ser_test+0x37>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ser_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
lea    0xea8(%rip),%rsi
lea    0x40(%rsp),%rdi
mov    $0xa8,%edx
call   1050 <memcpy@plt>
lea    0x44(%rsp),%rbp
xor    %r13d,%r13d
mov    %rsp,%r14
lea    0x20(%rsp),%r15
jmp    1200 <ser_test+0xb0>
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <dec_u4_be@plt>
xor    %edi,%edi
cmp    %eax,%r12d
sete   %dil
call   1040 <assert@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   1060 <enc_u4_be@plt>
xor    %edi,%edi
cmp    %eax,%ebx
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
mov    %r12d,%esi
call   1060 <enc_u4_be@plt>
xor    %edi,%edi
cmp    %eax,%ebx
sete   %dil
call   1040 <assert@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   1030 <b_diff@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
add    $0x1,%r13
add    $0x18,%rbp
cmp    $0x7,%r13
je     125a <ser_test+0x10a>
movaps 0xdf9(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0xff,0x10(%rsp)
lea    0x0(,%r13,2),%rax
add    %r13,%rax
mov    0x40(%rsp,%rax,8),%r12d
mov    $0x0,%ebx
test   %r12d,%r12d
je     1190 <ser_test+0x40>
xor    %ebx,%ebx
mov    %r12d,%ecx
mov    %r12d,%eax
nopl   0x0(%rax)
sar    $0x7,%eax
mov    0x0(%rbp,%rbx,4),%edx
mov    %edx,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x7f,%ecx
mov    %eax,%ecx
ja     1240 <ser_test+0xf0>
jmp    1190 <ser_test+0x40>
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.ser_test.a = [7 x [6 x i32]] [[6 x i32] [i32 1, i32 1, i32 255, i32 255, i32 255, i32 255], [6 x i32] [i32 129, i32 129, i32 1, i32 255, i32 255, i32 255], [6 x i32] [i32 16513, i32 129, i32 129, i32 1, i32 255, i32 255], [6 x i32] [i32 2113665, i32 129, i32 129, i32 129, i32 1, i32 255], [6 x i32] [i32 270549121, i32 129, i32 129, i32 129, i32 129, i32 1], [6 x i32] [i32 272679429, i32 129, i32 130, i32 131, i32 132, i32 5], [6 x i32] [i32 1350615297, i32 133, i32 132, i32 131, i32 130, i32 1]]
define void @ser_test() {
%1 = alloca [7 x [6 x i32]]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [5 x i32]
%8 = alloca i32*
%9 = alloca [5 x i32]
%10 = alloca i32
%11 = bitcast [7 x [6 x i32]]* %1 to i8*
store i32 7, i32* %3
store i32 0, i32* %2
br label %12
12: ; preds = %86, %0
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %89
16: ; preds = %12
%17 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
store i32 255, i32* %17
%18 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 1
store i32 255, i32* %18
%19 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 2
store i32 255, i32* %19
%20 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 3
store i32 255, i32* %20
%21 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 4
store i32 255, i32* %21
%22 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
store i32* %22, i32** %8
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [7 x [6 x i32]], [7 x [6 x i32]]* %1, i64 0, i64 %24
%26 = getelementptr inbounds [6 x i32], [6 x i32]* %25, i64 0, i64 1
store i32* %26, i32** %6
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [7 x [6 x i32]], [7 x [6 x i32]]* %1, i64 0, i64 %28
%30 = getelementptr inbounds [6 x i32], [6 x i32]* %29, i64 0, i64 0
%31 = load i32, i32* %30
store i32 %31, i32* %4
store i32 0, i32* %10
br label %32
32: ; preds = %35, %16
%33 = load i32, i32* %4
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %47
35: ; preds = %32
%36 = load i32, i32* %4
%37 = and i32 %36, 127
store i32 %37, i32* %5
%38 = load i32, i32* %4
%39 = ashr i32 %38, 7
store i32 %39, i32* %4
%40 = load i32*, i32** %6
%41 = getelementptr inbounds i32, i32* %40, i32 1
store i32* %41, i32** %6
%42 = load i32, i32* %40
%43 = load i32*, i32** %8
%44 = getelementptr inbounds i32, i32* %43, i32 1
store i32* %44, i32** %8
store i32 %42, i32* %43
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %32
47: ; preds = %32
%48 = load i32, i32* %2
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [7 x [6 x i32]], [7 x [6 x i32]]* %1, i64 0, i64 %49
%51 = getelementptr inbounds [6 x i32], [6 x i32]* %50, i64 0, i64 0
%52 = load i32, i32* %51
%53 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%54 = call i32 @dec_u4_be(i32* %53, i32* null)
%55 = icmp eq i32 %52, %54
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = load i32, i32* %10
%59 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 0
%60 = load i32, i32* %2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [7 x [6 x i32]], [7 x [6 x i32]]* %1, i64 0, i64 %61
%63 = getelementptr inbounds [6 x i32], [6 x i32]* %62, i64 0, i64 0
%64 = load i32, i32* %63
%65 = call i32 @enc_u4_be(i32* %59, i32 %64)
%66 = icmp eq i32 %58, %65
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i32, i32* %10
%70 = load i32, i32* %2
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [7 x [6 x i32]], [7 x [6 x i32]]* %1, i64 0, i64 %71
%73 = getelementptr inbounds [6 x i32], [6 x i32]* %72, i64 0, i64 0
%74 = load i32, i32* %73
%75 = call i32 @enc_u4_be(i32* null, i32 %74)
%76 = icmp eq i32 %69, %75
%77 = zext i1 %76 to i32
%78 = call i32 @assert(i32 %77)
%79 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%80 = load i32, i32* %10
%81 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 0
%82 = call i64 @b_diff(i32* %79, i32 %80, i32* %81)
%83 = icmp eq i64 %82, 0
%84 = zext i1 %83 to i32
%85 = call i32 @assert(i32 %84)
br label %86
86: ; preds = %47
%87 = load i32, i32* %2
%88 = add nsw i32 %87, 1
store i32 %88, i32* %2
br label %12
89: ; preds = %12
ret void
}

LLVM IR (-O2):
@__const.ser_test.a = [7 x [6 x i32]] [[6 x i32] [i32 1, i32 1, i32 255, i32 255, i32 255, i32 255], [6 x i32] [i32 129, i32 129, i32 1, i32 255, i32 255, i32 255], [6 x i32] [i32 16513, i32 129, i32 129, i32 1, i32 255, i32 255], [6 x i32] [i32 2113665, i32 129, i32 129, i32 129, i32 1, i32 255], [6 x i32] [i32 270549121, i32 129, i32 129, i32 129, i32 129, i32 1], [6 x i32] [i32 272679429, i32 129, i32 130, i32 131, i32 132, i32 5], [6 x i32] [i32 1350615297, i32 133, i32 132, i32 131, i32 130, i32 1]]
define void @ser_test() {
%1 = alloca [7 x [6 x i32]]
%2 = alloca [5 x i32]
%3 = alloca [5 x i32]
%4 = bitcast [7 x [6 x i32]]* %1 to i8*
%5 = bitcast [5 x i32]* %2 to i8*
%6 = bitcast [5 x i32]* %3 to i8*
%7 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 4
%9 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%10 = bitcast [5 x i32]* %2 to <4 x i32>*
br label %11
11: ; preds = %0, %29
%12 = phi i64 [ 0, %0 ], [ %47, %29 ]
store <4 x i32> <i32 255, i32 255, i32 255, i32 255>, <4 x i32>* %10
store i32 255, i32* %8
%13 = getelementptr inbounds [7 x [6 x i32]], [7 x [6 x i32]]* %1, i64 0, i64 %12, i64 0
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %29, label %16
16: ; preds = %11
%17 = getelementptr inbounds [7 x [6 x i32]], [7 x [6 x i32]]* %1, i64 0, i64 %12, i64 1
br label %18
18: ; preds = %16, %18
%19 = phi i32 [ %27, %18 ], [ 0, %16 ]
%20 = phi i32* [ %26, %18 ], [ %7, %16 ]
%21 = phi i32* [ %24, %18 ], [ %17, %16 ]
%22 = phi i32 [ %23, %18 ], [ %14, %16 ]
%23 = ashr i32 %22, 7
%24 = getelementptr inbounds i32, i32* %21, i64 1
%25 = load i32, i32* %21
%26 = getelementptr inbounds i32, i32* %20, i64 1
store i32 %25, i32* %20
%27 = add nuw nsw i32 %19, 1
%28 = icmp ult i32 %22, 128
br i1 %28, label %29, label %18
29: ; preds = %18, %11
%30 = phi i32 [ 0, %11 ], [ %27, %18 ]
%31 = call i32 @dec_u4_be(i32* %7, i32* null)
%32 = icmp eq i32 %14, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call i32 @enc_u4_be(i32* %9, i32 %14)
%36 = icmp eq i32 %30, %35
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = call i32 @enc_u4_be(i32* null, i32 %14)
%40 = icmp eq i32 %30, %39
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = call i64 @b_diff(i32* %7, i32 %30, i32* %9)
%44 = icmp eq i64 %43, 0
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = add nuw nsw i64 %12, 1
%48 = icmp eq i64 %47, 7
br i1 %48, label %49, label %11
49: ; preds = %29
ret void
}