#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*/ printf(char *, unsigned short);
unsigned short assemble(char a, char b) {
  unsigned short x = a;
  printf("%d\n", a);
  printf("%d\n", b);
  x <<= 8;
  printf("%d\n", x);
  x = x | b;
  printf("%d\n", x);
  return x;
}


x86 assembly (clang, -O0):
<assemble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
movsbl -0x1(%rbp),%eax
mov    %ax,-0x4(%rbp)
movsbl -0x1(%rbp),%eax
lea    0xec9(%rip),%rdi
movzwl %ax,%esi
call   1030 <printf@plt>
movsbl -0x2(%rbp),%eax
lea    0xeb6(%rip),%rdi
movzwl %ax,%esi
call   1030 <printf@plt>
movzwl -0x4(%rbp),%eax
shl    $0x8,%eax
mov    %ax,-0x4(%rbp)
lea    0xe9c(%rip),%rdi
movzwl -0x4(%rbp),%esi
call   1030 <printf@plt>
movzwl -0x4(%rbp),%eax
movsbl -0x2(%rbp),%ecx
or     %ecx,%eax
mov    %ax,-0x4(%rbp)
lea    0xe7e(%rip),%rdi
movzwl -0x4(%rbp),%esi
call   1030 <printf@plt>
movzwl -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assemble>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
movzwl %bp,%esi
lea    0xede(%rip),%r14
mov    %r14,%rdi
call   1030 <printf@plt>
movzwl %bx,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
shl    $0x8,%ebp
movzwl %bp,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
or     %ebx,%ebp
movzwl %bp,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define zeroext i16 @assemble(i8 signext %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i16
store i8 %0, i8* %3
store i8 %1, i8* %4
%6 = load i8, i8* %3
%7 = sext i8 %6 to i16
store i16 %7, i16* %5
%8 = load i8, i8* %3
%9 = sext i8 %8 to i16
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %9)
%11 = load i8, i8* %4
%12 = sext i8 %11 to i16
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %12)
%14 = load i16, i16* %5
%15 = zext i16 %14 to i32
%16 = shl i32 %15, 8
%17 = trunc i32 %16 to i16
store i16 %17, i16* %5
%18 = load i16, i16* %5
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %18)
%20 = load i16, i16* %5
%21 = zext i16 %20 to i32
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = or i32 %21, %23
%25 = trunc i32 %24 to i16
store i16 %25, i16* %5
%26 = load i16, i16* %5
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %26)
%28 = load i16, i16* %5
ret i16 %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define zeroext i16 @assemble(i8 signext %0, i8 signext %1) {
%3 = sext i8 %0 to i16
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %3)
%5 = sext i8 %1 to i16
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %5)
%7 = shl nsw i16 %3, 8
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %7)
%9 = or i16 %7, %5
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 zeroext %9)
ret i16 %9
}