#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 clear_bit(int, int);
int /*<<< orphan*/ isBitset(int, int);
int modify_bit(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int set_bit(int, int);
int main() {
  int number, pos;
  char ops;
  int state;
  printf("Enter the Number : ");
  scanf("%d", &number);
  printf("\nEnter your choice :");
  printf("1.set bit\n2.Modify a bit\n3.Is bit set\n4.Clear bit");
  scanf(" %c", &ops);
  printf("\nEnter the position :");
  scanf(" %d", &pos);
  switch (ops) {
  case '1':
    printf("Inside 1\n");
    printf("After Modification : %d \n", set_bit(number, pos));
    break;
  case '2':
    printf("Inside 2\n");
    printf("\nEnter the new state :");
    scanf("%d", &state);
    printf("After Modification : %d\n", modify_bit(number, pos, state));
    break;
  case '3':
    printf("inside 3\n");
    printf("number %x \n", number);
    printf((isBitset(number, pos)) ? "SET\n" : "NOT SET\n");
    break;
  case '4':
    return clear_bit(number, pos);
    break;
  default:
    printf("Invalid\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1040 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xefc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x21(%rbp),%al
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xeb0(%rip),%rdi
lea    -0xd(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x21(%rbp),%al
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xea8(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <scanf@plt>
movsbl -0xd(%rbp),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     12ef <main+0x18f>
mov    -0x20(%rbp),%rax
lea    0xdf9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <set_bit@plt>
mov    %eax,%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fd <main+0x19d>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe25(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <modify_bit@plt>
mov    %eax,%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fd <main+0x19d>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1070 <isBitset@plt>
mov    %eax,%ecx
lea    0xe3b(%rip),%rdi
lea    0xe38(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fd <main+0x19d>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <clear_bit@plt>
mov    %eax,-0x4(%rbp)
jmp    1304 <main+0x1a4>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xefa(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb0(%rip),%rdi
lea    0x3(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea9(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
movsbl 0x3(%rsp),%eax
add    $0xffffffcf,%eax
cmp    $0x3,%eax
ja     1229 <main+0xb9>
lea    0xe04(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeee(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%esi
call   1070 <set_bit@plt>
lea    0xe64(%rip),%rdi
xor    %ebx,%ebx
jmp    1281 <main+0x111>
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
jmp    12e5 <main+0x175>
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
lea    0xe56(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe29(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
call   1030 <modify_bit@plt>
lea    0xe39(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12e5 <main+0x175>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%esi
lea    0xe30(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%esi
call   1080 <isBitset@plt>
test   %eax,%eax
lea    0xe1d(%rip),%rax
lea    0xe1a(%rip),%rdi
cmove  %rax,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12e5 <main+0x175>
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%esi
call   1060 <clear_bit@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter the Number : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\0AEnter your choice :\00"
@.str.3 = [50 x i8] c"1.set bit\0A2.Modify a bit\0A3.Is bit set\0A4.Clear bit\00"
@.str.4 = [4 x i8] c" %c\00"
@.str.5 = [22 x i8] c"\0AEnter the position :\00"
@.str.6 = [4 x i8] c" %d\00"
@.str.7 = [10 x i8] c"Inside 1\0A\00"
@.str.8 = [26 x i8] c"After Modification : %d \0A\00"
@.str.9 = [10 x i8] c"Inside 2\0A\00"
@.str.10 = [23 x i8] c"\0AEnter the new state :\00"
@.str.11 = [25 x i8] c"After Modification : %d\0A\00"
@.str.12 = [10 x i8] c"inside 3\0A\00"
@.str.13 = [12 x i8] c"number %x \0A\00"
@.str.14 = [5 x i8] c"SET\0A\00"
@.str.15 = [9 x i8] c"NOT SET\0A\00"
@.str.16 = [9 x i8] c"Invalid\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
switch i32 %14, label %45 [
i32 49, label %15
i32 50, label %21
i32 51, label %30
i32 52, label %41
]
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = call i32 @set_bit(i32 %17, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %19)
br label %47
21: ; preds = %0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = load i32, i32* %5
%28 = call i32 @modify_bit(i32 %25, i32 %26, i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %28)
br label %47
30: ; preds = %0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i64 0, i64 0))
%32 = load i32, i32* %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = call i32 @isBitset(i32 %34, i32 %35)
%37 = icmp ne i32 %36, 0
%38 = zext i1 %37 to i64
%39 = select i1 %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0)
%40 = call i32 (i8*, ...) @printf(i8* %39)
br label %47
41: ; preds = %0
%42 = load i32, i32* %2
%43 = load i32, i32* %3
%44 = call i32 @clear_bit(i32 %42, i32 %43)
store i32 %44, i32* %1
br label %48
45: ; preds = %0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i64 0, i64 0))
br label %47
47: ; preds = %45, %30, %21, %15
store i32 0, i32* %1
br label %48
48: ; preds = %47, %41
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter the Number : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\0AEnter your choice :\00"
@.str.3 = [50 x i8] c"1.set bit\0A2.Modify a bit\0A3.Is bit set\0A4.Clear bit\00"
@.str.4 = [4 x i8] c" %c\00"
@.str.5 = [22 x i8] c"\0AEnter the position :\00"
@.str.6 = [4 x i8] c" %d\00"
@.str.8 = [26 x i8] c"After Modification : %d \0A\00"
@.str.10 = [23 x i8] c"\0AEnter the new state :\00"
@.str.11 = [25 x i8] c"After Modification : %d\0A\00"
@.str.13 = [12 x i8] c"number %x \0A\00"
@.str.14 = [5 x i8] c"SET\0A\00"
@.str.15 = [9 x i8] c"NOT SET\0A\00"
@str = [9 x i8] c"inside 3\00"
@str.17 = [9 x i8] c"Inside 2\00"
@str.18 = [9 x i8] c"Inside 1\00"
@str.19 = [8 x i8] c"Invalid\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %4 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
switch i32 %16, label %46 [
i32 49, label %17
i32 50, label %23
i32 51, label %32
i32 52, label %42
]
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.18, i64 0, i64 0))
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = call i32 @set_bit(i32 %19, i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %21)
br label %48
23: ; preds = %0
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.17, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%27 = load i32, i32* %1
%28 = load i32, i32* %2
%29 = load i32, i32* %4
%30 = call i32 @modify_bit(i32 %27, i32 %28, i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %30)
br label %48
32: ; preds = %0
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%34 = load i32, i32* %1
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %1
%37 = load i32, i32* %2
%38 = call i32 @isBitset(i32 %36, i32 %37)
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %40)
br label %48
42: ; preds = %0
%43 = load i32, i32* %1
%44 = load i32, i32* %2
%45 = call i32 @clear_bit(i32 %43, i32 %44)
br label %48
46: ; preds = %0
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.19, i64 0, i64 0))
br label %48
48: ; preds = %17, %23, %32, %46, %42
%49 = phi i32 [ %45, %42 ], [ 0, %46 ], [ 0, %32 ], [ 0, %23 ], [ 0, %17 ]
ret i32 %49
}