#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);
int /*<<< orphan*/ stderr;
char *version_name(unsigned int);
void parse_sh_supported_versions(char *data, unsigned offset, unsigned length,
                                 int json) {
  unsigned pos = offset;
  unsigned version_code;
  const char *name = NULL;
  if (json)
    printf("\"version\": ");
  version_code = read_uint(data, pos, 2);
  name = version_name(version_code);
  if (name == NULL) {
    name = "unknown";
    fprintf(stderr, "WARNING! Unknown version (%#.4x)\n", version_code);
  }
  if (json)
    printf("{\"name\": \"%s\", \"id\": \"%#.4x\"}", name, version_code);
  else
    printf("\t\t%s\n", name);
}


x86 assembly (clang, -O0):
<parse_sh_supported_versions>:
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)
movq   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117b <parse_sh_supported_versions+0x3b>
lea    0xe8c(%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,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <version_name@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c9 <parse_sh_supported_versions+0x89>
lea    0xe5f(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     11ed <parse_sh_supported_versions+0xad>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ff <parse_sh_supported_versions+0xbf>
mov    -0x28(%rbp),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_sh_supported_versions>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
test   %ecx,%ecx
je     115e <parse_sh_supported_versions+0x1e>
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x2,%edx
call   1060 <read_uint@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <version_name@plt>
test   %rax,%rax
je     1197 <parse_sh_supported_versions+0x57>
test   %r14d,%r14d
je     11ba <parse_sh_supported_versions+0x7a>
lea    0xeaf(%rip),%rdi
mov    %rax,%rsi
mov    %ebp,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
lea    0xe57(%rip),%rax
test   %r14d,%r14d
jne    1180 <parse_sh_supported_versions+0x40>
lea    0xe93(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"\22version\22: \00"
@.str.1 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"WARNING! Unknown version (%#.4x)\0A\00"
@.str.3 = [30 x i8] c"{\22name\22: \22%s\22, \22id\22: \22%#.4x\22}\00"
@.str.4 = [6 x i8] c"\09\09%s\0A\00"
define void @parse_sh_supported_versions(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 i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %6
store i32 %12, i32* %9
store i8* null, i8** %11
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %4
%18 = load i8*, i8** %5
%19 = load i32, i32* %9
%20 = call i32 @read_uint(i8* %18, i32 %19, i32 2)
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = call i8* @version_name(i32 %21)
store i8* %22, i8** %11
%23 = load i8*, i8** %11
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %17
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %11
%26 = load i32, i32* @stderr
%27 = load i32, i32* %10
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %25, %17
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8*, i8** %11
%34 = load i32, i32* %10
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %33, i32 %34)
br label %39
36: ; preds = %29
%37 = load i8*, i8** %11
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %32
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"\22version\22: \00"
@.str.1 = [8 x i8] c"unknown\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"WARNING! Unknown version (%#.4x)\0A\00"
@.str.3 = [30 x i8] c"{\22name\22: \22%s\22, \22id\22: \22%#.4x\22}\00"
@.str.4 = [6 x i8] c"\09\09%s\0A\00"
define void @parse_sh_supported_versions(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = tail call i32 @read_uint(i8* %0, i32 %1, i32 2)
%10 = tail call i8* @version_name(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %15
15: ; preds = %12, %8
%16 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %12 ], [ %10, %8 ]
br i1 %5, label %19, label %17
17: ; preds = %15
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %16, i32 %9)
br label %21
19: ; preds = %15
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %16)
br label %21
21: ; preds = %19, %17
ret void
}