#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int read_uint(char *, unsigned int, int);
char *sigalg_name(unsigned int);
int /*<<< orphan*/ stderr;
void parse_signature_algorithms(char *data, unsigned offset, unsigned length,
                                int json) {
  unsigned pos = offset;
  unsigned sigalgs_length = read_uint(data, pos, 2);
  unsigned sigalg_code;
  const char *name = NULL;
  int i = 0;
  pos += 2;
  if (json)
    printf("\"sigalg_list\": [");
  for (; pos < offset + length; pos += 2) {
    if (json && i != 0)
      printf(", ");
    sigalg_code = read_uint(data, pos, 2);
    name = sigalg_name(sigalg_code);
    if (name == NULL) {
      name = "unknown";
      fprintf(stderr, "WARNING! Unknown signature algorithm (%#.4x)\n",
              sigalg_code);
    }
    if (json)
      printf("{\"name\": \"%s\", \"id\": \"%#.4x\"}", name, sigalg_code);
    else
      printf("\t\t%s\n", name);
    i++;
  }
  if (json)
    printf("]");
}


x86 assembly (clang, -O0):
<parse_signature_algorithms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x2,%edx
call   1060 <read_uint@plt>
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     119f <parse_signature_algorithms+0x5f>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a4 <parse_signature_algorithms+0x64>
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jae    1272 <parse_signature_algorithms+0x132>
cmpl   $0x0,-0x14(%rbp)
je     11d7 <parse_signature_algorithms+0x97>
cmpl   $0x0,-0x2c(%rbp)
je     11d7 <parse_signature_algorithms+0x97>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x2,%edx
call   1060 <read_uint@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <sigalg_name@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1225 <parse_signature_algorithms+0xe5>
lea    0xe0b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xdfc(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1249 <parse_signature_algorithms+0x109>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125b <parse_signature_algorithms+0x11b>
mov    -0x28(%rbp),%rsi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    11a4 <parse_signature_algorithms+0x64>
cmpl   $0x0,-0x14(%rbp)
je     128a <parse_signature_algorithms+0x14a>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_signature_algorithms>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
mov    $0x2,%edx
call   1070 <read_uint@plt>
test   %ebx,%ebx
je     1181 <parse_signature_algorithms+0x31>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    %ebp,%r14d
add    $0x2,%ebp
cmp    %r14d,%ebp
jae    1240 <parse_signature_algorithms+0xf0>
xor    %r13d,%r13d
jmp    11bd <parse_signature_algorithms+0x6d>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xec1(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x2,%ebp
cmp    %r14d,%ebp
jae    1240 <parse_signature_algorithms+0xf0>
add    $0xffffffff,%r13d
setb   %al
test   %ebx,%ebx
je     11da <parse_signature_algorithms+0x8a>
test   %al,%al
je     11da <parse_signature_algorithms+0x8a>
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x2,%edx
call   1070 <read_uint@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1040 <sigalg_name@plt>
test   %rax,%rax
je     1200 <parse_signature_algorithms+0xb0>
test   %ebx,%ebx
jne    1227 <parse_signature_algorithms+0xd7>
jmp    11a0 <parse_signature_algorithms+0x50>
xchg   %ax,%ax
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
mov    %r12d,%edx
call   1060 <fprintf@plt>
lea    0xdf5(%rip),%rax
test   %ebx,%ebx
je     11a0 <parse_signature_algorithms+0x50>
lea    0xe1c(%rip),%rdi
mov    %rax,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11b1 <parse_signature_algorithms+0x61>
test   %ebx,%ebx
je     125c <parse_signature_algorithms+0x10c>
mov    $0x5d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\22sigalg_list\22: [\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.3 = [46 x i8] c"WARNING! Unknown signature algorithm (%#.4x)\0A\00"
@.str.4 = [30 x i8] c"{\22name\22: \22%s\22, \22id\22: \22%#.4x\22}\00"
@.str.5 = [6 x i8] c"\09\09%s\0A\00"
@.str.6 = [2 x i8] c"]\00"
define void @parse_signature_algorithms(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* %6
store i32 %14, i32* %9
%15 = load i8*, i8** %5
%16 = load i32, i32* %9
%17 = call i32 @read_uint(i8* %15, i32 %16, i32 2)
store i32 %17, i32* %10
store i8* null, i8** %12
store i32 0, i32* %13
%18 = load i32, i32* %9
%19 = add i32 %18, 2
store i32 %19, i32* %9
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %4
br label %25
25: ; preds = %64, %24
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = add i32 %27, %28
%30 = icmp ult i32 %26, %29
br i1 %30, label %31, label %67
31: ; preds = %25
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32, i32* %13
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %34, %31
%40 = load i8*, i8** %5
%41 = load i32, i32* %9
%42 = call i32 @read_uint(i8* %40, i32 %41, i32 2)
store i32 %42, i32* %11
%43 = load i32, i32* %11
%44 = call i8* @sigalg_name(i32 %43)
store i8* %44, i8** %12
%45 = load i8*, i8** %12
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %51
47: ; preds = %39
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %12
%48 = load i32, i32* @stderr
%49 = load i32, i32* %11
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %47, %39
%52 = load i32, i32* %8
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load i8*, i8** %12
%56 = load i32, i32* %11
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %55, i32 %56)
br label %61
58: ; preds = %51
%59 = load i8*, i8** %12
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %58, %54
%62 = load i32, i32* %13
%63 = add nsw i32 %62, 1
store i32 %63, i32* %13
br label %64
64: ; preds = %61
%65 = load i32, i32* %9
%66 = add i32 %65, 2
store i32 %66, i32* %9
br label %25
67: ; preds = %25
%68 = load i32, i32* %8
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %72
72: ; preds = %70, %67
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"\22sigalg_list\22: [\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.3 = [46 x i8] c"WARNING! Unknown signature algorithm (%#.4x)\0A\00"
@.str.4 = [30 x i8] c"{\22name\22: \22%s\22, \22id\22: \22%#.4x\22}\00"
@.str.5 = [6 x i8] c"\09\09%s\0A\00"
define void @parse_signature_algorithms(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @read_uint(i8* %0, i32 %1, i32 2)
%6 = icmp ne i32 %3, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %4
%10 = add i32 %2, %1
%11 = add i32 %1, 2
%12 = icmp ult i32 %11, %10
br i1 %12, label %13, label %37
13: ; preds = %9, %33
%14 = phi i32 [ %35, %33 ], [ %11, %9 ]
%15 = phi i32 [ %34, %33 ], [ 0, %9 ]
%16 = icmp ne i32 %15, 0
%17 = select i1 %6, i1 %16, i1 false
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = tail call i32 @read_uint(i8* %0, i32 %14, i32 2)
%22 = tail call i8* @sigalg_name(i32 %21)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %27
27: ; preds = %24, %20
%28 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %24 ], [ %22, %20 ]
br i1 %6, label %29, label %31
29: ; preds = %27
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %28, i32 %21)
br label %33
31: ; preds = %27
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %28)
br label %33
33: ; preds = %31, %29
%34 = add nuw nsw i32 %15, 1
%35 = add i32 %14, 2
%36 = icmp ult i32 %35, %10
br i1 %36, label %13, label %37
37: ; preds = %33, %9
br i1 %6, label %38, label %40
38: ; preds = %37
%39 = tail call i32 @putchar(i32 93)
br label %40
40: ; preds = %38, %37
ret void
}