#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 */
typedef int u_char;
typedef int /*<<< orphan*/ packed;
typedef int /*<<< orphan*/ num1;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int pack(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int *unpack(int);
int main() {
  int num1, num2;
  u_char packed, *unpacked;
  printf("Sizeof(num1) = %lu\n", sizeof(num1));
  printf("Enter two numbers in HEX : ");
  scanf("%i %i", &num1, &num2);
  printf("num1 = %XH\tnum2 = %XH\n", num1, num2);
  packed = pack(num1, num2);
  if (packed == (u_char)-1) {
    printf("Error: One of the number is greater than 0x0f\n");
    exit(1);
  }
  printf("sizeof(packed) = %lu\n", sizeof(packed));
  printf("Packed number = %XH or %dD\n", packed, packed);
  unpacked = unpack(packed);
  printf("Unpacked numbers = %XH and %XH\n", unpacked[0], unpacked[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea9(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <scanf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <pack@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11d8 <main+0x88>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe9d(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
call   1050 <unpack@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea3(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <scanf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   1040 <pack@plt>
cmp    $0xffffffff,%eax
je     120d <main+0xad>
mov    %eax,%ebx
lea    0xe80(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe83(%rip),%rdi
mov    %ebx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <unpack@plt>
mov    (%rax),%esi
mov    0x4(%rax),%edx
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Sizeof(num1) = %lu\0A\00"
@.str.1 = [28 x i8] c"Enter two numbers in HEX : \00"
@.str.2 = [6 x i8] c"%i %i\00"
@.str.3 = [23 x i8] c"num1 = %XH\09num2 = %XH\0A\00"
@.str.4 = [47 x i8] c"Error: One of the number is greater than 0x0f\0A\00"
@.str.5 = [22 x i8] c"sizeof(packed) = %lu\0A\00"
@.str.6 = [28 x i8] c"Packed number = %XH or %dD\0A\00"
@.str.7 = [32 x i8] c"Unpacked numbers = %XH and %XH\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 4)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3)
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %10)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 @pack(i32 %12, i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i64 4)
%22 = load i32, i32* %4
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %22, i32 %23)
%25 = load i32, i32* %4
%26 = call i32* @unpack(i32 %25)
store i32* %26, i32** %5
%27 = load i32*, i32** %5
%28 = getelementptr inbounds i32, i32* %27, i64 0
%29 = load i32, i32* %28
%30 = load i32*, i32** %5
%31 = getelementptr inbounds i32, i32* %30, i64 1
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %29, i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Sizeof(num1) = %lu\0A\00"
@.str.1 = [28 x i8] c"Enter two numbers in HEX : \00"
@.str.2 = [6 x i8] c"%i %i\00"
@.str.3 = [23 x i8] c"num1 = %XH\09num2 = %XH\0A\00"
@.str.5 = [22 x i8] c"sizeof(packed) = %lu\0A\00"
@.str.6 = [28 x i8] c"Packed number = %XH or %dD\0A\00"
@.str.7 = [32 x i8] c"Unpacked numbers = %XH and %XH\0A\00"
@str = [46 x i8] c"Error: One of the number is greater than 0x0f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2)
%8 = load i32, i32* %1
%9 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %1
%12 = load i32, i32* %2
%13 = call i32 @pack(i32 %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i64 4)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %13, i32 %13)
%21 = call i32* @unpack(i32 %13)
%22 = load i32, i32* %21
%23 = getelementptr inbounds i32, i32* %21, i64 1
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %22, i32 %24)
ret i32 0
}