#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 uint16_t;
struct vm86_regs {
  int esp;
  int /*<<< orphan*/ ss;
};

/* Variables and functions */
scalar_t__ seg_to_linear(int /*<<< orphan*/, int);
void pushw(struct vm86_regs *r, int val) {
  r->esp = (r->esp & ~0xffff) | ((r->esp - 2) & 0xffff);
  *(uint16_t *)seg_to_linear(r->ss, r->esp) = val;
}


x86 assembly (clang, -O0):
<pushw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
and    $0xffff0000,%ecx
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sub    $0x2,%eax
and    $0xffff,%eax
or     %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
call   1030 <seg_to_linear@plt>
mov    -0x10(%rbp),%ecx
mov    %ecx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pushw>:
push   %rbx
mov    %esi,%ebx
mov    (%rdi),%ecx
mov    0x4(%rdi),%eax
mov    %ecx,%edx
and    $0xffff0000,%edx
add    $0xfffe,%ecx
movzwl %cx,%esi
or     %edx,%esi
mov    %esi,(%rdi)
mov    %eax,%edi
call   1030 <seg_to_linear@plt>
mov    %ebx,(%rax)
pop    %rbx
ret

LLVM IR (-O0):
%struct.vm86_regs = type { i32, i32 }
define void @pushw(%struct.vm86_regs* %0, i32 %1) {
%3 = alloca %struct.vm86_regs*
%4 = alloca i32
store %struct.vm86_regs* %0, %struct.vm86_regs** %3
store i32 %1, i32* %4
%5 = load %struct.vm86_regs*, %struct.vm86_regs** %3
%6 = getelementptr inbounds %struct.vm86_regs, %struct.vm86_regs* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = and i32 %7, -65536
%9 = load %struct.vm86_regs*, %struct.vm86_regs** %3
%10 = getelementptr inbounds %struct.vm86_regs, %struct.vm86_regs* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = sub nsw i32 %11, 2
%13 = and i32 %12, 65535
%14 = or i32 %8, %13
%15 = load %struct.vm86_regs*, %struct.vm86_regs** %3
%16 = getelementptr inbounds %struct.vm86_regs, %struct.vm86_regs* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* %4
%18 = load %struct.vm86_regs*, %struct.vm86_regs** %3
%19 = getelementptr inbounds %struct.vm86_regs, %struct.vm86_regs* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load %struct.vm86_regs*, %struct.vm86_regs** %3
%22 = getelementptr inbounds %struct.vm86_regs, %struct.vm86_regs* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i64 @seg_to_linear(i32 %20, i32 %23)
%25 = inttoptr i64 %24 to i32*
store i32 %17, i32* %25
ret void
}

LLVM IR (-O2):
%struct.vm86_regs = type { i32, i32 }
define void @pushw(%struct.vm86_regs* nocapture %0, i32 %1) {
%3 = getelementptr inbounds %struct.vm86_regs, %struct.vm86_regs* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = and i32 %4, -65536
%6 = add i32 %4, 65534
%7 = and i32 %6, 65535
%8 = or i32 %7, %5
store i32 %8, i32* %3
%9 = getelementptr inbounds %struct.vm86_regs, %struct.vm86_regs* %0, i64 0, i32 1
%10 = load i32, i32* %9
%11 = tail call i64 @seg_to_linear(i32 %10, i32 %8)
%12 = inttoptr i64 %11 to i32*
store i32 %1, i32* %12
ret void
}