#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*/ HECMW_vis_print_exit(char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned short);
scalar_t__ transform_hex(char);
unsigned short int change_short_int_order(unsigned short int n) {
  char c_buf[10], newc_buf[10], changed_buf[10];
  unsigned short int i, m, digit;
  sprintf(c_buf, "%x", n);
  m = 0;
  while (c_buf[m] != '\0')
    m++;
  if (m > 4)
    HECMW_vis_print_exit("there is something wrong for the unsigned short int");
  for (i = 0; i < 4 - m; i++)
    newc_buf[i] = '0';
  for (i = 0; i < m; i++)
    newc_buf[4 - m + i] = c_buf[i];
  newc_buf[4] = '\0';
  changed_buf[0] = newc_buf[2];
  changed_buf[1] = newc_buf[3];
  changed_buf[2] = newc_buf[0];
  changed_buf[3] = newc_buf[1];
  changed_buf[4] = '\0';
  digit = 0;
  for (i = 0; i < 4; i++) {
    digit *= 16;
    digit += transform_hex(changed_buf[i]);
  }
  return (digit);
}


x86 assembly (clang, -O0):
<change_short_int_order>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
lea    -0xc(%rbp),%rdi
lea    0xeb6(%rip),%rsi
movzwl -0x2(%rbp),%edx
call   1040 <sprintf@plt>
movw   $0x0,-0x24(%rbp)
movzwl -0x24(%rbp),%eax
movsbl -0xc(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     117c <change_short_int_order+0x4c>
mov    -0x24(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x24(%rbp)
jmp    1159 <change_short_int_order+0x29>
movzwl -0x24(%rbp),%eax
cmp    $0x4,%eax
jle    1195 <change_short_int_order+0x65>
lea    0xe73(%rip),%rdi
call   1030 <HECMW_vis_print_exit@plt>
movw   $0x0,-0x22(%rbp)
movzwl -0x22(%rbp),%eax
movzwl -0x24(%rbp),%edx
mov    $0x4,%ecx
sub    %edx,%ecx
cmp    %ecx,%eax
jge    11cc <change_short_int_order+0x9c>
movzwl -0x22(%rbp),%eax
movb   $0x30,-0x16(%rbp,%rax,1)
mov    -0x22(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x22(%rbp)
jmp    119b <change_short_int_order+0x6b>
movw   $0x0,-0x22(%rbp)
movzwl -0x22(%rbp),%eax
movzwl -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    1212 <change_short_int_order+0xe2>
movzwl -0x22(%rbp),%eax
mov    -0xc(%rbp,%rax,1),%cl
movzwl -0x24(%rbp),%edx
mov    $0x4,%eax
sub    %edx,%eax
movzwl -0x22(%rbp),%edx
add    %edx,%eax
cltq
mov    %cl,-0x16(%rbp,%rax,1)
mov    -0x22(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x22(%rbp)
jmp    11d2 <change_short_int_order+0xa2>
movb   $0x0,-0x12(%rbp)
mov    -0x14(%rbp),%al
mov    %al,-0x20(%rbp)
mov    -0x13(%rbp),%al
mov    %al,-0x1f(%rbp)
mov    -0x16(%rbp),%al
mov    %al,-0x1e(%rbp)
mov    -0x15(%rbp),%al
mov    %al,-0x1d(%rbp)
movb   $0x0,-0x1c(%rbp)
movw   $0x0,-0x26(%rbp)
movw   $0x0,-0x22(%rbp)
movzwl -0x22(%rbp),%eax
cmp    $0x4,%eax
jge    1283 <change_short_int_order+0x153>
movzwl -0x26(%rbp),%eax
shl    $0x4,%eax
mov    %ax,-0x26(%rbp)
movzwl -0x22(%rbp),%eax
movsbl -0x20(%rbp,%rax,1),%edi
call   1050 <transform_hex@plt>
mov    %rax,%rcx
movzwl -0x26(%rbp),%eax
add    %rcx,%rax
mov    %ax,-0x26(%rbp)
mov    -0x22(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x22(%rbp)
jmp    123e <change_short_int_order+0x10e>
movzwl -0x26(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_short_int_order>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%edx
lea    0xe9d(%rip),%rsi
lea    0xe(%rsp),%rdi
call   1060 <sprintf@plt>
mov    $0xffff,%bp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
movzwl %bp,%ebx
cmpb   $0x0,0xe(%rsp,%rbx,1)
jne    1180 <change_short_int_order+0x30>
movzwl %bp,%r14d
cmp    $0x5,%r14w
jb     11a6 <change_short_int_order+0x56>
lea    0xe64(%rip),%rdi
call   1030 <HECMW_vis_print_exit@plt>
jmp    11d3 <change_short_int_order+0x83>
cmp    $0x4,%bp
je     11d3 <change_short_int_order+0x83>
mov    $0x4,%eax
sub    %r14d,%eax
cmp    $0x2,%eax
mov    $0x1,%edx
cmovge %eax,%edx
lea    0x4(%rsp),%rdi
mov    $0x30,%esi
call   1040 <memset@plt>
test   %bp,%bp
je     11f2 <change_short_int_order+0xa2>
mov    $0x4,%eax
sub    %r14d,%eax
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x4,%rdi
lea    0xe(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
movsbl 0x6(%rsp),%edi
movsbl 0x7(%rsp),%ebx
movsbl 0x4(%rsp),%r15d
movsbl 0x5(%rsp),%r14d
call   1070 <transform_hex@plt>
mov    %rax,%rbp
shl    $0x4,%ebp
mov    %ebx,%edi
call   1070 <transform_hex@plt>
mov    %rax,%rbx
add    %ebp,%ebx
shl    $0x4,%ebx
mov    %r15d,%edi
call   1070 <transform_hex@plt>
mov    %rax,%rbp
add    %ebx,%ebp
shl    $0x4,%ebp
mov    %r14d,%edi
call   1070 <transform_hex@plt>
add    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
@.str.1 = [52 x i8] c"there is something wrong for the unsigned short int\00"
define zeroext i16 @change_short_int_order(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca [10 x i8]
%4 = alloca [10 x i8]
%5 = alloca [10 x i8]
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
store i16 %0, i16* %2
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%10 = load i16, i16* %2
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i16 zeroext %10)
store i16 0, i16* %7
br label %12
12: ; preds = %19, %1
%13 = load i16, i16* %7
%14 = zext i16 %13 to i64
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i16, i16* %7
%21 = add i16 %20, 1
store i16 %21, i16* %7
br label %12
22: ; preds = %12
%23 = load i16, i16* %7
%24 = zext i16 %23 to i32
%25 = icmp sgt i32 %24, 4
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @HECMW_vis_print_exit(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
store i16 0, i16* %6
br label %29
29: ; preds = %40, %28
%30 = load i16, i16* %6
%31 = zext i16 %30 to i32
%32 = load i16, i16* %7
%33 = zext i16 %32 to i32
%34 = sub nsw i32 4, %33
%35 = icmp slt i32 %31, %34
br i1 %35, label %36, label %43
36: ; preds = %29
%37 = load i16, i16* %6
%38 = zext i16 %37 to i64
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %38
store i8 48, i8* %39
br label %40
40: ; preds = %36
%41 = load i16, i16* %6
%42 = add i16 %41, 1
store i16 %42, i16* %6
br label %29
43: ; preds = %29
store i16 0, i16* %6
br label %44
44: ; preds = %63, %43
%45 = load i16, i16* %6
%46 = zext i16 %45 to i32
%47 = load i16, i16* %7
%48 = zext i16 %47 to i32
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %66
50: ; preds = %44
%51 = load i16, i16* %6
%52 = zext i16 %51 to i64
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = load i16, i16* %7
%56 = zext i16 %55 to i32
%57 = sub nsw i32 4, %56
%58 = load i16, i16* %6
%59 = zext i16 %58 to i32
%60 = add nsw i32 %57, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %61
store i8 %54, i8* %62
br label %63
63: ; preds = %50
%64 = load i16, i16* %6
%65 = add i16 %64, 1
store i16 %65, i16* %6
br label %44
66: ; preds = %44
%67 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 4
store i8 0, i8* %67
%68 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 2
%69 = load i8, i8* %68
%70 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
store i8 %69, i8* %70
%71 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 3
%72 = load i8, i8* %71
%73 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 1
store i8 %72, i8* %73
%74 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%75 = load i8, i8* %74
%76 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 2
store i8 %75, i8* %76
%77 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 1
%78 = load i8, i8* %77
%79 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 3
store i8 %78, i8* %79
%80 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 4
store i8 0, i8* %80
store i16 0, i16* %8
store i16 0, i16* %6
br label %81
81: ; preds = %99, %66
%82 = load i16, i16* %6
%83 = zext i16 %82 to i32
%84 = icmp slt i32 %83, 4
br i1 %84, label %85, label %102
85: ; preds = %81
%86 = load i16, i16* %8
%87 = zext i16 %86 to i32
%88 = mul nsw i32 %87, 16
%89 = trunc i32 %88 to i16
store i16 %89, i16* %8
%90 = load i16, i16* %6
%91 = zext i16 %90 to i64
%92 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %91
%93 = load i8, i8* %92
%94 = call i64 @transform_hex(i8 signext %93)
%95 = load i16, i16* %8
%96 = zext i16 %95 to i64
%97 = add nsw i64 %96, %94
%98 = trunc i64 %97 to i16
store i16 %98, i16* %8
br label %99
99: ; preds = %85
%100 = load i16, i16* %6
%101 = add i16 %100, 1
store i16 %101, i16* %6
br label %81
102: ; preds = %81
%103 = load i16, i16* %8
ret i16 %103
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
@.str.1 = [52 x i8] c"there is something wrong for the unsigned short int\00"
define zeroext i16 @change_short_int_order(i16 zeroext %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i16 zeroext %0)
br label %9
9: ; preds = %9, %1
%10 = phi i16 [ 0, %1 ], [ %15, %9 ]
%11 = zext i16 %10 to i64
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
%15 = add i16 %10, 1
br i1 %14, label %16, label %9
16: ; preds = %9
%17 = zext i16 %10 to i32
%18 = icmp ugt i16 %10, 4
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @HECMW_vis_print_exit(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %28
21: ; preds = %16
%22 = icmp eq i16 %10, 4
br i1 %22, label %28, label %23
23: ; preds = %21
%24 = sub nsw i32 4, %17
%25 = call i32 @llvm.smax.i32(i32 %24, i32 1)
%26 = zext i32 %25 to i64
%27 = icmp eq i16 %10, 0
br i1 %27, label %32, label %28
28: ; preds = %21, %19, %23
%29 = sub nsw i32 4, %17
%30 = sext i32 %29 to i64
%31 = getelementptr [10 x i8], [10 x i8]* %4, i64 0, i64 %30
br label %32
32: ; preds = %28, %23
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 2
%34 = load i8, i8* %33
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 3
%36 = load i8, i8* %35
%37 = load i8, i8* %7
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 1
%39 = load i8, i8* %38
%40 = tail call i64 @transform_hex(i8 signext %34)
%41 = trunc i64 %40 to i16
%42 = shl i16 %41, 4
%43 = tail call i64 @transform_hex(i8 signext %36)
%44 = trunc i64 %43 to i16
%45 = add i16 %42, %44
%46 = shl i16 %45, 4
%47 = tail call i64 @transform_hex(i8 signext %37)
%48 = trunc i64 %47 to i16
%49 = add i16 %46, %48
%50 = shl i16 %49, 4
%51 = tail call i64 @transform_hex(i8 signext %39)
%52 = trunc i64 %51 to i16
%53 = add i16 %50, %52
ret i16 %53
}