#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 ntohs(unsigned short);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
void dump_short(char *output, int maxlen, void *value, int len) {
  if (len == (int)sizeof(unsigned short))
    snprintf(output, maxlen, "%d", ntohs((*((unsigned short *)(value)))));
  else
    snprintf(output, maxlen, "Invalid SHORT");
}


x86 assembly (clang, -O0):
<dump_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jne    1176 <dump_short+0x56>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movzwl (%rax),%edi
call   1040 <ntohs@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    %eax,%ecx
lea    0xe96(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    118b <dump_short+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xe7f(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_short>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
cmp    $0x2,%ecx
jne    1150 <dump_short+0x30>
movzwl (%rdx),%edi
call   1040 <ntohs@plt>
lea    0xec4(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%ecx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <snprintf@plt>
lea    0xeac(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [14 x i8] c"Invalid SHORT\00"
define void @dump_short(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %4
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = load i8*, i8** %7
%15 = bitcast i8* %14 to i16*
%16 = load i16, i16* %15
%17 = call i32 @ntohs(i16 zeroext %16)
%18 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %12, i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %23
19: ; preds = %4
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %20, i32 %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %19, %11
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [14 x i8] c"Invalid SHORT\00"
define void @dump_short(i8* %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = icmp eq i32 %3, 2
br i1 %5, label %6, label %11
6: ; preds = %4
%7 = bitcast i8* %2 to i16*
%8 = load i16, i16* %7
%9 = tail call i32 @ntohs(i16 zeroext %8)
%10 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %13
11: ; preds = %4
%12 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
ret void
}