#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 *, ...);
int /*<<< orphan*/ scanf(char *, unsigned int *);
main(void) {
  unsigned int val, startBitNum, noOfBits, bitFieldVal, maskVal = 0x0;
  int ii;
  printf("Enter an unsingned integer in Hex format\n");
  scanf("%x", &val);
  printf("Enter a start bit number\n");
  scanf("%d", &startBitNum);
  printf("Enter no of bits\n");
  scanf("%d", &noOfBits);
  printf("Enter bit Field Value\n");
  scanf("%x", &bitFieldVal);
  for (ii = 0; ii < noOfBits; ii++) {
    if (ii)
      maskVal <<= 1;
    maskVal |= 0x1;
  }
  val = (bitFieldVal << startBitNum) | (val & (~(maskVal << startBitNum)));
  printf("value = %x\n", val);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xede(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe85(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11eb <main+0xcb>
cmpl   $0x0,-0x1c(%rbp)
je     11d4 <main+0xb4>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b5 <main+0x95>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    %cl,%eax
mov    -0x8(%rbp),%ecx
mov    %ecx,-0x20(%rbp)
mov    -0x18(%rbp),%edx
mov    -0xc(%rbp),%ecx
shl    %cl,%edx
mov    -0x20(%rbp),%ecx
xor    $0xffffffff,%edx
and    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
lea    0xe99(%rip),%rbx
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
mov    0x10(%rsp),%edi
test   %edi,%edi
je     11c4 <main+0x94>
lea    -0x1(%rdi),%ecx
mov    %edi,%eax
and    $0x3,%eax
cmp    $0x3,%ecx
jae    11c8 <main+0x98>
xor    %edx,%edx
xor    %esi,%esi
jmp    11e4 <main+0xb4>
xor    %esi,%esi
jmp    1201 <main+0xd1>
and    $0xfffffffc,%edi
xor    %edx,%edx
xor    %esi,%esi
nop
test   %edx,%edx
setne  %cl
shl    %cl,%esi
shl    $0x3,%esi
or     $0xf,%esi
add    $0x4,%edx
cmp    %edx,%edi
jne    11d0 <main+0xa0>
test   %eax,%eax
je     1201 <main+0xd1>
neg    %eax
xor    %edi,%edi
nopl   0x0(%rax)
cmp    %edi,%edx
setne  %cl
shl    %cl,%esi
or     $0x1,%esi
add    $0xffffffff,%edi
cmp    %edi,%eax
jne    11f0 <main+0xc0>
mov    0xc(%rsp),%eax
mov    0x14(%rsp),%cl
shl    %cl,%eax
shl    %cl,%esi
not    %esi
and    0x8(%rsp),%esi
or     %eax,%esi
mov    %esi,0x8(%rsp)
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Enter an unsingned integer in Hex format\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [26 x i8] c"Enter a start bit number\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [18 x i8] c"Enter no of bits\0A\00"
@.str.5 = [23 x i8] c"Enter bit Field Value\0A\00"
@.str.6 = [12 x i8] c"value = %x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 0, i32* %7
br label %16
16: ; preds = %29, %0
%17 = load i32, i32* %7
%18 = load i32, i32* %4
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %6
%25 = shl i32 %24, 1
store i32 %25, i32* %6
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* %6
%28 = or i32 %27, 1
store i32 %28, i32* %6
br label %29
29: ; preds = %26
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %16
32: ; preds = %16
%33 = load i32, i32* %5
%34 = load i32, i32* %3
%35 = shl i32 %33, %34
%36 = load i32, i32* %2
%37 = load i32, i32* %6
%38 = load i32, i32* %3
%39 = shl i32 %37, %38
%40 = xor i32 %39, -1
%41 = and i32 %36, %40
%42 = or i32 %35, %41
store i32 %42, i32* %2
%43 = load i32, i32* %2
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%x\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.6 = [12 x i8] c"value = %x\0A\00"
@str = [41 x i8] c"Enter an unsingned integer in Hex format\00"
@str.7 = [25 x i8] c"Enter a start bit number\00"
@str.8 = [17 x i8] c"Enter no of bits\00"
@str.9 = [22 x i8] c"Enter bit Field Value\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
br i1 %18, label %53, label %19
19: ; preds = %0
%20 = add i32 %17, -1
%21 = and i32 %17, 3
%22 = icmp ult i32 %20, 3
br i1 %22, label %37, label %23
23: ; preds = %19
%24 = and i32 %17, -4
br label %25
25: ; preds = %25, %23
%26 = phi i32 [ 0, %23 ], [ %34, %25 ]
%27 = phi i32 [ 0, %23 ], [ %33, %25 ]
%28 = phi i32 [ 0, %23 ], [ %35, %25 ]
%29 = icmp ne i32 %26, 0
%30 = zext i1 %29 to i32
%31 = shl i32 %27, %30
%32 = shl i32 %31, 3
%33 = or i32 %32, 15
%34 = add nuw nsw i32 %26, 4
%35 = add i32 %28, 4
%36 = icmp eq i32 %35, %24
br i1 %36, label %37, label %25
37: ; preds = %25, %19
%38 = phi i32 [ undef, %19 ], [ %33, %25 ]
%39 = phi i32 [ 0, %19 ], [ %34, %25 ]
%40 = phi i32 [ 0, %19 ], [ %33, %25 ]
%41 = icmp eq i32 %21, 0
br i1 %41, label %53, label %42
42: ; preds = %37, %42
%43 = phi i32 [ %50, %42 ], [ %39, %37 ]
%44 = phi i32 [ %49, %42 ], [ %40, %37 ]
%45 = phi i32 [ %51, %42 ], [ 0, %37 ]
%46 = icmp ne i32 %43, 0
%47 = zext i1 %46 to i32
%48 = shl i32 %44, %47
%49 = or i32 %48, 1
%50 = add nuw nsw i32 %43, 1
%51 = add i32 %45, 1
%52 = icmp eq i32 %51, %21
br i1 %52, label %53, label %42
53: ; preds = %37, %42, %0
%54 = phi i32 [ 0, %0 ], [ %38, %37 ], [ %49, %42 ]
%55 = load i32, i32* %4
%56 = load i32, i32* %2
%57 = shl i32 %55, %56
%58 = load i32, i32* %1
%59 = shl i32 %54, %56
%60 = xor i32 %59, -1
%61 = and i32 %58, %60
%62 = or i32 %61, %57
store i32 %62, i32* %1
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %62)
ret i32 0
}