#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 unsigned int int64_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ stderr;
unsigned int mul_lo_op(unsigned int size, unsigned int a, unsigned int b) {
  unsigned int mask;
  switch (size) {
  case 8:
    mask = 0xff;
    break;
  case 16:
    mask = 0xffff;
    break;
  case 32:
    mask = 0xffffffff;
    break;
  default:
    fprintf(stderr, "inv size in mul %d\n", size);
    exit(EXIT_FAILURE);
  }
  a &= mask;
  b &= mask;
  return ((int64_t)a * (int64_t)b) & mask;
}


x86 assembly (clang, -O0):
<mul_lo_op>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x8,%eax
je     1167 <mul_lo_op+0x47>
jmp    1145 <mul_lo_op+0x25>
mov    -0x14(%rbp),%eax
sub    $0x10,%eax
je     1173 <mul_lo_op+0x53>
jmp    1156 <mul_lo_op+0x36>
mov    -0x14(%rbp),%eax
sub    $0x20,%eax
je     117f <mul_lo_op+0x5f>
jmp    118b <mul_lo_op+0x6b>
movl   $0xff,-0x10(%rbp)
jmp    11b1 <mul_lo_op+0x91>
movl   $0xffff,-0x10(%rbp)
jmp    11b1 <mul_lo_op+0x91>
movl   $0xffffffff,-0x10(%rbp)
jmp    11b1 <mul_lo_op+0x91>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe62(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
and    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mul_lo_op>:
cmp    $0x8,%edi
je     1138 <mul_lo_op+0x18>
mov    %edi,%eax
cmp    $0x20,%edi
je     113f <mul_lo_op+0x1f>
cmp    $0x10,%eax
jne    1150 <mul_lo_op+0x30>
mov    $0xffff,%eax
jmp    1144 <mul_lo_op+0x24>
mov    $0xff,%eax
jmp    1144 <mul_lo_op+0x24>
mov    $0xffffffff,%eax
and    %eax,%esi
and    %eax,%edx
imul   %esi,%edx
and    %eax,%edx
mov    %edx,%eax
ret
push   %rax
mov    0x2e88(%rip),%rcx
mov    (%rcx),%edi
lea    0xe9f(%rip),%rsi
mov    %eax,%edx
call   1030 <fprintf@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"inv size in mul %d\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @mul_lo_op(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
switch i32 %8, label %12 [
i32 8, label %9
i32 16, label %10
i32 32, label %11
]
9: ; preds = %3
store i32 255, i32* %7
br label %18
10: ; preds = %3
store i32 65535, i32* %7
br label %18
11: ; preds = %3
store i32 -1, i32* %7
br label %18
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i32, i32* %4
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %11, %10, %9
%19 = load i32, i32* %7
%20 = load i32, i32* %5
%21 = and i32 %20, %19
store i32 %21, i32* %5
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = and i32 %23, %22
store i32 %24, i32* %6
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = mul i32 %25, %26
%28 = load i32, i32* %7
%29 = and i32 %27, %28
ret i32 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"inv size in mul %d\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @mul_lo_op(i32 %0, i32 %1, i32 %2) {
switch i32 %0, label %6 [
i32 8, label %11
i32 16, label %4
i32 32, label %5
]
4: ; preds = %3
br label %11
5: ; preds = %3
br label %11
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3, %5, %4
%12 = phi i32 [ -1, %5 ], [ 65535, %4 ], [ 255, %3 ]
%13 = and i32 %12, %1
%14 = and i32 %12, %2
%15 = mul i32 %13, %14
%16 = and i32 %15, %12
ret i32 %16
}