#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 */
unsigned short atoi(char *);
unsigned short endian_swap16(unsigned short);
int /*<<< orphan*/ endian_swap16bit(unsigned short *);
unsigned int endian_swap32(unsigned int);
int /*<<< orphan*/ endian_swap32bit(unsigned int *);
unsigned long long endian_swap64(unsigned long long);
int /*<<< orphan*/ endian_swap64bit(unsigned long long *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("args error");
    return -1;
  }
  unsigned short num16 = atoi(argv[1]);
  unsigned int num32 = num16;
  unsigned long long num64 = num32;
  printf("16bit - Num: %u, Hex: %04X\n", num16, num16);
  printf("32bit - Num: %u, Hex: %08X\n", num32, num32);
  printf("64bit - Num: %llu , ", num64);
  printf("Hex: %016llX\n", num64);
  unsigned short tmpnum16 = 0;
  unsigned int tmpnum32 = 0;
  unsigned long long tmpnum64 = 0;
  tmpnum16 = endian_swap16(num16);
  tmpnum32 = endian_swap32(num32);
  tmpnum64 = endian_swap64(num64);
  endian_swap16bit(&num16);
  endian_swap32bit(&num32);
  endian_swap64bit(&num64);
  printf("16bit - Num: %u, Hex: %04X\n", num16, num16);
  printf("32bit - Num: %u, Hex: %08X\n", num32, num32);
  printf("64bit - Num: %llu, Hex: %016llX\n", num64, num64);
  printf("16bit - Num: %u, Hex: %04X\n", tmpnum16, tmpnum16);
  printf("32bit - Num: %u, Hex: %08X\n", tmpnum32, tmpnum32);
  printf("64bit - Num: %llu, Hex: %016llX\n", tmpnum64, tmpnum64);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ba <main+0x3a>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <main+0x183>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rax,-0x20(%rbp)
movzwl -0x12(%rbp),%esi
movzwl -0x12(%rbp),%edx
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movw   $0x0,-0x22(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movzwl -0x12(%rbp),%edi
call   1080 <endian_swap16@plt>
mov    %ax,-0x22(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <endian_swap32@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <endian_swap64@plt>
mov    %rax,-0x30(%rbp)
lea    -0x12(%rbp),%rdi
call   1030 <endian_swap16bit@plt>
lea    -0x18(%rbp),%rdi
call   1070 <endian_swap32bit@plt>
lea    -0x20(%rbp),%rdi
call   10a0 <endian_swap64bit@plt>
movzwl -0x12(%rbp),%esi
movzwl -0x12(%rbp),%edx
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzwl -0x22(%rbp),%esi
movzwl -0x22(%rbp),%edx
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    12aa <main+0x12a>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %ax,0xa(%rsp)
movzwl %ax,%ebx
mov    %ebx,0xc(%rsp)
mov    %rbx,0x10(%rsp)
lea    0xe53(%rip),%r14
xor    %r12d,%r12d
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe57(%rip),%r15
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1080 <endian_swap16@plt>
mov    %eax,%r13d
mov    %ebx,%edi
call   1060 <endian_swap32@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <endian_swap64@plt>
mov    %rax,%rbx
lea    0xa(%rsp),%rdi
call   1030 <endian_swap16bit@plt>
lea    0xc(%rsp),%rdi
call   1070 <endian_swap32bit@plt>
lea    0x10(%rsp),%rdi
call   10a0 <endian_swap64bit@plt>
movzwl 0xa(%rsp),%edx
mov    %r14,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edx
mov    %r15,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rdx
lea    0xdef(%rip),%r14
mov    %r14,%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movzwl %r13w,%edx
lea    0xd8a(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12be <main+0x13e>
lea    0xd4f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"args error\00"
@.str.1 = [28 x i8] c"16bit - Num: %u, Hex: %04X\0A\00"
@.str.2 = [28 x i8] c"32bit - Num: %u, Hex: %08X\0A\00"
@.str.3 = [21 x i8] c"64bit - Num: %llu , \00"
@.str.4 = [14 x i8] c"Hex: %016llX\0A\00"
@.str.5 = [33 x i8] c"64bit - Num: %llu, Hex: %016llX\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca i32
%8 = alloca i64
%9 = alloca i16
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call zeroext i16 @atoi(i8* %19)
store i16 %20, i16* %6
%21 = load i16, i16* %6
%22 = zext i16 %21 to i32
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = zext i32 %23 to i64
store i64 %24, i64* %8
%25 = load i16, i16* %6
%26 = zext i16 %25 to i32
%27 = load i16, i16* %6
%28 = zext i16 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %28)
%30 = load i32, i32* %7
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %31)
%33 = load i64, i64* %8
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %33)
%35 = load i64, i64* %8
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i64 %35)
store i16 0, i16* %9
store i32 0, i32* %10
store i64 0, i64* %11
%37 = load i16, i16* %6
%38 = call zeroext i16 @endian_swap16(i16 zeroext %37)
store i16 %38, i16* %9
%39 = load i32, i32* %7
%40 = call i32 @endian_swap32(i32 %39)
store i32 %40, i32* %10
%41 = load i64, i64* %8
%42 = call i64 @endian_swap64(i64 %41)
store i64 %42, i64* %11
%43 = call i32 @endian_swap16bit(i16* %6)
%44 = call i32 @endian_swap32bit(i32* %7)
%45 = call i32 @endian_swap64bit(i64* %8)
%46 = load i16, i16* %6
%47 = zext i16 %46 to i32
%48 = load i16, i16* %6
%49 = zext i16 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %47, i32 %49)
%51 = load i32, i32* %7
%52 = load i32, i32* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %51, i32 %52)
%54 = load i64, i64* %8
%55 = load i64, i64* %8
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 %54, i64 %55)
%57 = load i16, i16* %9
%58 = zext i16 %57 to i32
%59 = load i16, i16* %9
%60 = zext i16 %59 to i32
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %58, i32 %60)
%62 = load i32, i32* %10
%63 = load i32, i32* %10
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %62, i32 %63)
%65 = load i64, i64* %11
%66 = load i64, i64* %11
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 %65, i64 %66)
store i32 0, i32* %3
br label %68
68: ; preds = %16, %14
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [11 x i8] c"args error\00"
@.str.1 = [28 x i8] c"16bit - Num: %u, Hex: %04X\0A\00"
@.str.2 = [28 x i8] c"32bit - Num: %u, Hex: %08X\0A\00"
@.str.3 = [21 x i8] c"64bit - Num: %llu , \00"
@.str.4 = [14 x i8] c"Hex: %016llX\0A\00"
@.str.5 = [33 x i8] c"64bit - Num: %llu, Hex: %016llX\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca i32
%5 = alloca i64
%6 = icmp eq i32 %0, 2
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %39
9: ; preds = %2
%10 = bitcast i16* %3 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call zeroext i16 @atoi(i8* %12)
store i16 %13, i16* %3
%14 = bitcast i32* %4 to i8*
%15 = zext i16 %13 to i32
store i32 %15, i32* %4
%16 = bitcast i64* %5 to i8*
%17 = zext i16 %13 to i64
store i64 %17, i64* %5
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %15)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %15)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %17)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i64 %17)
%22 = tail call zeroext i16 @endian_swap16(i16 zeroext %13)
%23 = tail call i32 @endian_swap32(i32 %15)
%24 = tail call i64 @endian_swap64(i64 %17)
%25 = call i32 @endian_swap16bit(i16* %3)
%26 = call i32 @endian_swap32bit(i32* %4)
%27 = call i32 @endian_swap64bit(i64* %5)
%28 = load i16, i16* %3
%29 = zext i16 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %29)
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %31)
%33 = load i64, i64* %5
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 %33, i64 %33)
%35 = zext i16 %22 to i32
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %23)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 %24, i64 %24)
br label %39
39: ; preds = %9, %7
%40 = phi i32 [ -1, %7 ], [ 0, %9 ]
ret i32 %40
}