#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 /*<<< orphan*/ kSimpleBER;
typedef int /*<<< orphan*/ kOctetStringDER;
typedef int /*<<< orphan*/ kOctetStringBER;
typedef int /*<<< orphan*/ kNSSDER;
typedef int /*<<< orphan*/ kNSSBER;
typedef int /*<<< orphan*/ kIndefDER;
typedef int /*<<< orphan*/ kIndefBER;

/* Variables and functions */
scalar_t__ do_ber_convert(char *, int const *, int, int const *, int);
int test_ber_convert(void) {
  static const uint8_t kSimpleBER[] = {0x01, 0x01, 0x00};
  static const uint8_t kIndefBER[] = {0x30, 0x80, 0x01, 0x01, 0x02, 0x00, 0x00};
  static const uint8_t kIndefDER[] = {0x30, 0x03, 0x01, 0x01, 0x02};
  static const uint8_t kOctetStringBER[] = {0x24, 0x80, 0x04, 0x02, 0,    1,
                                            0x04, 0x02, 2,    3,    0x00, 0x00};
  static const uint8_t kOctetStringDER[] = {0x04, 0x04, 0, 1, 2, 3};
  static const uint8_t kNSSBER[] = {
      0x30, 0x80, 0x02, 0x01, 0x03, 0x30, 0x80, 0x06, 0x09, 0x2a, 0x86, 0x48,
      0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x80, 0x24, 0x80, 0x04, 0x04,
      0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x39,
      0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
      0x00, 0x04, 0x14, 0x84, 0x98, 0xfc, 0x66, 0x33, 0xee, 0xba, 0xe7, 0x90,
      0xc1, 0xb6, 0xe8, 0x8f, 0xfe, 0x1d, 0xc5, 0xa5, 0x97, 0x93, 0x3e, 0x04,
      0x10, 0x38, 0x62, 0xc6, 0x44, 0x12, 0xd5, 0x30, 0x00, 0xf8, 0xf2, 0x1b,
      0xf0, 0x6e, 0x10, 0x9b, 0xb8, 0x02, 0x02, 0x07, 0xd0, 0x00, 0x00,
  };
  static const uint8_t kNSSDER[] = {
      0x30, 0x53, 0x02, 0x01, 0x03, 0x30, 0x13, 0x06, 0x09, 0x2a, 0x86,
      0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x06, 0x04, 0x04,
      0x01, 0x02, 0x03, 0x04, 0x30, 0x39, 0x30, 0x21, 0x30, 0x09, 0x06,
      0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14, 0x84,
      0x98, 0xfc, 0x66, 0x33, 0xee, 0xba, 0xe7, 0x90, 0xc1, 0xb6, 0xe8,
      0x8f, 0xfe, 0x1d, 0xc5, 0xa5, 0x97, 0x93, 0x3e, 0x04, 0x10, 0x38,
      0x62, 0xc6, 0x44, 0x12, 0xd5, 0x30, 0x00, 0xf8, 0xf2, 0x1b, 0xf0,
      0x6e, 0x10, 0x9b, 0xb8, 0x02, 0x02, 0x07, 0xd0,
  };
  return do_ber_convert("kSimpleBER", kSimpleBER, sizeof(kSimpleBER),
                        kSimpleBER, sizeof(kSimpleBER)) &&
         do_ber_convert("kIndefBER", kIndefDER, sizeof(kIndefDER), kIndefBER,
                        sizeof(kIndefBER)) &&
         do_ber_convert("kOctetStringBER", kOctetStringDER,
                        sizeof(kOctetStringDER), kOctetStringBER,
                        sizeof(kOctetStringBER)) &&
         do_ber_convert("kNSSBER", kNSSDER, sizeof(kNSSDER), kNSSBER,
                        sizeof(kNSSBER));
}


x86 assembly (clang, -O0):
<test_ber_convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0x1255(%rip),%rdi
lea    0xeda(%rip),%rcx
mov    $0xc,%r8d
mov    %rcx,%rsi
mov    %r8d,%edx
call   1030 <do_ber_convert@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1(%rbp)
je     11e6 <test_ber_convert+0xd6>
lea    0x122f(%rip),%rdi
lea    0xed9(%rip),%rsi
mov    $0x14,%edx
lea    0xead(%rip),%rcx
mov    $0x1c,%r8d
call   1030 <do_ber_convert@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1(%rbp)
je     11e6 <test_ber_convert+0xd6>
lea    0x1202(%rip),%rdi
lea    0xef2(%rip),%rsi
mov    $0x18,%edx
lea    0xeb6(%rip),%rcx
mov    $0x30,%r8d
call   1030 <do_ber_convert@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1(%rbp)
je     11e6 <test_ber_convert+0xd6>
lea    0x11db(%rip),%rdi
lea    0x105b(%rip),%rsi
mov    $0x154,%edx
lea    0xecf(%rip),%rcx
mov    $0x17c,%r8d
call   1030 <do_ber_convert@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1(%rbp)
mov    -0x1(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ber_convert>:
push   %rbx
lea    0x125c(%rip),%rdi
lea    0xee1(%rip),%rcx
mov    %rcx,%rsi
mov    $0xc,%edx
mov    $0xc,%r8d
call   1030 <do_ber_convert@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11be <test_ber_convert+0xae>
lea    0x123b(%rip),%rdi
lea    0xee5(%rip),%rsi
lea    0xebe(%rip),%rcx
mov    $0x14,%edx
mov    $0x1c,%r8d
call   1030 <do_ber_convert@plt>
test   %rax,%rax
je     11be <test_ber_convert+0xae>
lea    0x121b(%rip),%rdi
lea    0xf0b(%rip),%rsi
lea    0xed4(%rip),%rcx
mov    $0x18,%edx
mov    $0x30,%r8d
call   1030 <do_ber_convert@plt>
test   %rax,%rax
je     11be <test_ber_convert+0xae>
lea    0x1201(%rip),%rdi
lea    0x1081(%rip),%rsi
lea    0xefa(%rip),%rcx
mov    $0x154,%edx
mov    $0x17c,%r8d
call   1030 <do_ber_convert@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@test_ber_convert.kSimpleBER = internal constant [3 x i32] [i32 1, i32 1, i32 0]
@test_ber_convert.kIndefBER = internal constant [7 x i32] [i32 48, i32 128, i32 1, i32 1, i32 2, i32 0, i32 0]
@test_ber_convert.kIndefDER = internal constant [5 x i32] [i32 48, i32 3, i32 1, i32 1, i32 2]
@test_ber_convert.kOctetStringBER = internal constant [12 x i32] [i32 36, i32 128, i32 4, i32 2, i32 0, i32 1, i32 4, i32 2, i32 2, i32 3, i32 0, i32 0]
@test_ber_convert.kOctetStringDER = internal constant [6 x i32] [i32 4, i32 4, i32 0, i32 1, i32 2, i32 3]
@test_ber_convert.kNSSBER = internal constant [95 x i32] [i32 48, i32 128, i32 2, i32 1, i32 3, i32 48, i32 128, i32 6, i32 9, i32 42, i32 134, i32 72, i32 134, i32 247, i32 13, i32 1, i32 7, i32 1, i32 160, i32 128, i32 36, i32 128, i32 4, i32 4, i32 1, i32 2, i32 3, i32 4, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 48, i32 57, i32 48, i32 33, i32 48, i32 9, i32 6, i32 5, i32 43, i32 14, i32 3, i32 2, i32 26, i32 5, i32 0, i32 4, i32 20, i32 132, i32 152, i32 252, i32 102, i32 51, i32 238, i32 186, i32 231, i32 144, i32 193, i32 182, i32 232, i32 143, i32 254, i32 29, i32 197, i32 165, i32 151, i32 147, i32 62, i32 4, i32 16, i32 56, i32 98, i32 198, i32 68, i32 18, i32 213, i32 48, i32 0, i32 248, i32 242, i32 27, i32 240, i32 110, i32 16, i32 155, i32 184, i32 2, i32 2, i32 7, i32 208, i32 0, i32 0]
@test_ber_convert.kNSSDER = internal constant [85 x i32] [i32 48, i32 83, i32 2, i32 1, i32 3, i32 48, i32 19, i32 6, i32 9, i32 42, i32 134, i32 72, i32 134, i32 247, i32 13, i32 1, i32 7, i32 1, i32 160, i32 6, i32 4, i32 4, i32 1, i32 2, i32 3, i32 4, i32 48, i32 57, i32 48, i32 33, i32 48, i32 9, i32 6, i32 5, i32 43, i32 14, i32 3, i32 2, i32 26, i32 5, i32 0, i32 4, i32 20, i32 132, i32 152, i32 252, i32 102, i32 51, i32 238, i32 186, i32 231, i32 144, i32 193, i32 182, i32 232, i32 143, i32 254, i32 29, i32 197, i32 165, i32 151, i32 147, i32 62, i32 4, i32 16, i32 56, i32 98, i32 198, i32 68, i32 18, i32 213, i32 48, i32 0, i32 248, i32 242, i32 27, i32 240, i32 110, i32 16, i32 155, i32 184, i32 2, i32 2, i32 7, i32 208]
@.str = [11 x i8] c"kSimpleBER\00"
@.str.1 = [10 x i8] c"kIndefBER\00"
@.str.2 = [16 x i8] c"kOctetStringBER\00"
@.str.3 = [8 x i8] c"kNSSBER\00"
define i32 @test_ber_convert() {
%1 = call i64 @do_ber_convert(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* getelementptr inbounds ([3 x i32], [3 x i32]* @test_ber_convert.kSimpleBER, i64 0, i64 0), i32 12, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @test_ber_convert.kSimpleBER, i64 0, i64 0), i32 12)
%2 = icmp ne i64 %1, 0
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = call i64 @do_ber_convert(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* getelementptr inbounds ([5 x i32], [5 x i32]* @test_ber_convert.kIndefDER, i64 0, i64 0), i32 20, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @test_ber_convert.kIndefBER, i64 0, i64 0), i32 28)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = call i64 @do_ber_convert(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32* getelementptr inbounds ([6 x i32], [6 x i32]* @test_ber_convert.kOctetStringDER, i64 0, i64 0), i32 24, i32* getelementptr inbounds ([12 x i32], [12 x i32]* @test_ber_convert.kOctetStringBER, i64 0, i64 0), i32 48)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = call i64 @do_ber_convert(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* getelementptr inbounds ([85 x i32], [85 x i32]* @test_ber_convert.kNSSDER, i64 0, i64 0), i32 340, i32* getelementptr inbounds ([95 x i32], [95 x i32]* @test_ber_convert.kNSSBER, i64 0, i64 0), i32 380)
%11 = icmp ne i64 %10, 0
br label %12
12: ; preds = %9, %6, %3, %0
%13 = phi i1 [ false, %6 ], [ false, %3 ], [ false, %0 ], [ %11, %9 ]
%14 = zext i1 %13 to i32
ret i32 %14
}

LLVM IR (-O2):
@test_ber_convert.kSimpleBER = internal constant [3 x i32] [i32 1, i32 1, i32 0]
@test_ber_convert.kIndefBER = internal constant [7 x i32] [i32 48, i32 128, i32 1, i32 1, i32 2, i32 0, i32 0]
@test_ber_convert.kIndefDER = internal constant [5 x i32] [i32 48, i32 3, i32 1, i32 1, i32 2]
@test_ber_convert.kOctetStringBER = internal constant [12 x i32] [i32 36, i32 128, i32 4, i32 2, i32 0, i32 1, i32 4, i32 2, i32 2, i32 3, i32 0, i32 0]
@test_ber_convert.kOctetStringDER = internal constant [6 x i32] [i32 4, i32 4, i32 0, i32 1, i32 2, i32 3]
@test_ber_convert.kNSSBER = internal constant [95 x i32] [i32 48, i32 128, i32 2, i32 1, i32 3, i32 48, i32 128, i32 6, i32 9, i32 42, i32 134, i32 72, i32 134, i32 247, i32 13, i32 1, i32 7, i32 1, i32 160, i32 128, i32 36, i32 128, i32 4, i32 4, i32 1, i32 2, i32 3, i32 4, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 48, i32 57, i32 48, i32 33, i32 48, i32 9, i32 6, i32 5, i32 43, i32 14, i32 3, i32 2, i32 26, i32 5, i32 0, i32 4, i32 20, i32 132, i32 152, i32 252, i32 102, i32 51, i32 238, i32 186, i32 231, i32 144, i32 193, i32 182, i32 232, i32 143, i32 254, i32 29, i32 197, i32 165, i32 151, i32 147, i32 62, i32 4, i32 16, i32 56, i32 98, i32 198, i32 68, i32 18, i32 213, i32 48, i32 0, i32 248, i32 242, i32 27, i32 240, i32 110, i32 16, i32 155, i32 184, i32 2, i32 2, i32 7, i32 208, i32 0, i32 0]
@test_ber_convert.kNSSDER = internal constant [85 x i32] [i32 48, i32 83, i32 2, i32 1, i32 3, i32 48, i32 19, i32 6, i32 9, i32 42, i32 134, i32 72, i32 134, i32 247, i32 13, i32 1, i32 7, i32 1, i32 160, i32 6, i32 4, i32 4, i32 1, i32 2, i32 3, i32 4, i32 48, i32 57, i32 48, i32 33, i32 48, i32 9, i32 6, i32 5, i32 43, i32 14, i32 3, i32 2, i32 26, i32 5, i32 0, i32 4, i32 20, i32 132, i32 152, i32 252, i32 102, i32 51, i32 238, i32 186, i32 231, i32 144, i32 193, i32 182, i32 232, i32 143, i32 254, i32 29, i32 197, i32 165, i32 151, i32 147, i32 62, i32 4, i32 16, i32 56, i32 98, i32 198, i32 68, i32 18, i32 213, i32 48, i32 0, i32 248, i32 242, i32 27, i32 240, i32 110, i32 16, i32 155, i32 184, i32 2, i32 2, i32 7, i32 208]
@.str = [11 x i8] c"kSimpleBER\00"
@.str.1 = [10 x i8] c"kIndefBER\00"
@.str.2 = [16 x i8] c"kOctetStringBER\00"
@.str.3 = [8 x i8] c"kNSSBER\00"
define i32 @test_ber_convert() {
%1 = tail call i64 @do_ber_convert(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* getelementptr inbounds ([3 x i32], [3 x i32]* @test_ber_convert.kSimpleBER, i64 0, i64 0), i32 12, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @test_ber_convert.kSimpleBER, i64 0, i64 0), i32 12)
%2 = icmp eq i64 %1, 0
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = tail call i64 @do_ber_convert(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* getelementptr inbounds ([5 x i32], [5 x i32]* @test_ber_convert.kIndefDER, i64 0, i64 0), i32 20, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @test_ber_convert.kIndefBER, i64 0, i64 0), i32 28)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i64 @do_ber_convert(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32* getelementptr inbounds ([6 x i32], [6 x i32]* @test_ber_convert.kOctetStringDER, i64 0, i64 0), i32 24, i32* getelementptr inbounds ([12 x i32], [12 x i32]* @test_ber_convert.kOctetStringBER, i64 0, i64 0), i32 48)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = tail call i64 @do_ber_convert(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* getelementptr inbounds ([85 x i32], [85 x i32]* @test_ber_convert.kNSSDER, i64 0, i64 0), i32 340, i32* getelementptr inbounds ([95 x i32], [95 x i32]* @test_ber_convert.kNSSBER, i64 0, i64 0), i32 380)
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %9, %6, %3, %0
%14 = phi i32 [ 0, %6 ], [ 0, %3 ], [ 0, %0 ], [ %12, %9 ]
ret i32 %14
}