#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 fnMaskBit(unsigned short, unsigned short);
unsigned short fnSetBit(unsigned short, unsigned short);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned short *);
int main(void) {
  unsigned short uNum, uPos;
  printf("\nEnter a value\n");
  scanf("%hu", &uNum);
  printf("\nEnter bit uPosition (1-16) to set to one\n");
  scanf("%hu", &uPos);
  uNum = fnSetBit(uNum, uPos);
  printf("\nValue after setting the specified bit = %hu\n", uNum);
  printf("\nEnter a value\n");
  scanf("%hu", &uNum);
  printf("\nEnter bit uPosition (1-16) to mask to zero\n");
  scanf("%hu", &uPos);
  uNum = fnMaskBit(uNum, uPos);
  printf("\nValue after masking the specified bit = %hu\n", uNum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0x6(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x6(%rbp),%ax
movzwl %ax,%edi
movzwl -0x8(%rbp),%esi
call   1030 <fnSetBit@plt>
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4a(%rip),%rdi
lea    -0x6(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2c(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x6(%rbp),%ax
movzwl %ax,%edi
movzwl -0x8(%rbp),%esi
call   1050 <fnMaskBit@plt>
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xf2b(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe92(%rip),%rbx
lea    0x4(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
lea    0x6(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
movzwl 0x4(%rsp),%edi
movzwl 0x6(%rsp),%esi
call   1040 <fnSetBit@plt>
mov    %ax,0x4(%rsp)
movzwl %ax,%esi
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
movzwl 0x4(%rsp),%edi
movzwl 0x6(%rsp),%esi
call   1060 <fnMaskBit@plt>
mov    %ax,0x4(%rsp)
movzwl %ax,%esi
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"\0AEnter a value\0A\00"
@.str.1 = [4 x i8] c"%hu\00"
@.str.2 = [43 x i8] c"\0AEnter bit uPosition (1-16) to set to one\0A\00"
@.str.3 = [46 x i8] c"\0AValue after setting the specified bit = %hu\0A\00"
@.str.4 = [45 x i8] c"\0AEnter bit uPosition (1-16) to mask to zero\0A\00"
@.str.5 = [46 x i8] c"\0AValue after masking the specified bit = %hu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %2)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %3)
%8 = load i16, i16* %2
%9 = load i16, i16* %3
%10 = call zeroext i16 @fnSetBit(i16 zeroext %8, i16 zeroext %9)
store i16 %10, i16* %2
%11 = load i16, i16* %2
%12 = zext i16 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %2)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %3)
%18 = load i16, i16* %2
%19 = load i16, i16* %3
%20 = call zeroext i16 @fnMaskBit(i16 zeroext %18, i16 zeroext %19)
store i16 %20, i16* %2
%21 = load i16, i16* %2
%22 = zext i16 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%hu\00"
@.str.3 = [46 x i8] c"\0AValue after setting the specified bit = %hu\0A\00"
@.str.5 = [46 x i8] c"\0AValue after masking the specified bit = %hu\0A\00"
@str.6 = [42 x i8] c"\0AEnter bit uPosition (1-16) to set to one\00"
@str.7 = [15 x i8] c"\0AEnter a value\00"
@str.8 = [44 x i8] c"\0AEnter bit uPosition (1-16) to mask to zero\00"
define i32 @main() {
%1 = alloca i16
%2 = alloca i16
%3 = bitcast i16* %1 to i8*
%4 = bitcast i16* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.6, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %2)
%9 = load i16, i16* %1
%10 = load i16, i16* %2
%11 = call zeroext i16 @fnSetBit(i16 zeroext %9, i16 zeroext %10)
store i16 %11, i16* %1
%12 = zext i16 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %1)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.8, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i16* %2)
%18 = load i16, i16* %1
%19 = load i16, i16* %2
%20 = call zeroext i16 @fnMaskBit(i16 zeroext %18, i16 zeroext %19)
store i16 %20, i16* %1
%21 = zext i16 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %21)
ret i32 0
}