#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ check_intInput(unsigned int *, unsigned int *,
                                  unsigned int *, unsigned int *);
int exchange_bits(unsigned int, unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int get_max(int, int);
int get_min(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main() {
  printf("Enter decimal: ");
  unsigned int n, p, q, k;
  check_intInput(&n, &p, &q, &k);
  int bigger = get_max((int)p, (int)q);
  int smaller = get_min((int)p, (int)q);
  if ((bigger + k) > 32) {
    fprintf(stderr, "out of range");
    exit(EXIT_FAILURE);
  } else if ((smaller + k) >= bigger) {
    fprintf(stderr, "overlapping");
    exit(EXIT_FAILURE);
  }
  int result = exchange_bits(n, p, q, k);
  printf("result: %u", result);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1040 <check_intInput@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1060 <get_max@plt>
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <get_min@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    $0x20,%eax
jbe    11f0 <main+0x80>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jb     1222 <main+0xb2>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1227 <main+0xb7>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1080 <exchange_bits@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
lea    0x8(%rsp),%rcx
call   1040 <check_intInput@plt>
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
call   1060 <get_max@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
call   1030 <get_min@plt>
mov    0x8(%rsp),%ecx
lea    (%rcx,%rbx,1),%edx
cmp    $0x21,%edx
jae    11f5 <main+0x85>
add    %ecx,%eax
cmp    %ebx,%eax
jae    1207 <main+0x97>
mov    0xc(%rsp),%edi
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
call   1080 <exchange_bits@plt>
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
jmp    1217 <main+0xa7>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"Enter decimal: \00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"out of range\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"overlapping\00"
@.str.3 = [11 x i8] c"result: %u\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @check_intInput(i32* %2, i32* %3, i32* %4, i32* %5)
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = call i32 @get_max(i32 %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = call i32 @get_min(i32 %14, i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = add i32 %17, %18
%20 = icmp ugt i32 %19, 32
br i1 %20, label %21, label %26
21: ; preds = %0
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %0
%27 = load i32, i32* %7
%28 = load i32, i32* %5
%29 = add i32 %27, %28
%30 = load i32, i32* %6
%31 = icmp uge i32 %29, %30
br i1 %31, label %32, label %37
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %26
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = load i32, i32* %3
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = call i32 @exchange_bits(i32 %39, i32 %40, i32 %41, i32 %42)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = load i32, i32* @EXIT_SUCCESS
ret i32 %46
}

LLVM IR (-O2):
@.str = [16 x i8] c"Enter decimal: \00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"out of range\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"overlapping\00"
@.str.3 = [11 x i8] c"result: %u\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = call i32 @check_intInput(i32* %1, i32* %2, i32* %3, i32* %4)
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = call i32 @get_max(i32 %11, i32 %12)
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = call i32 @get_min(i32 %14, i32 %15)
%17 = load i32, i32* %4
%18 = add i32 %17, %13
%19 = icmp ugt i32 %18, 32
br i1 %19, label %20, label %25
20: ; preds = %0
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %0
%26 = add i32 %17, %16
%27 = icmp ult i32 %26, %13
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %25
%34 = load i32, i32* %1
%35 = load i32, i32* %2
%36 = load i32, i32* %3
%37 = call i32 @exchange_bits(i32 %34, i32 %35, i32 %36, i32 %17)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}