#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 int copy_bits(unsigned int, unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ print_binary(unsigned int);
int /*<<< orphan*/ printf(char *);
int scanf(char *, unsigned int *, unsigned int *, unsigned int *,
          unsigned int *);
int main(void) {
  printf("Enter source number, target number, and indexes i, j\n");
  printf("This will copy the bits in `source[i..j]` to `target[i..j]`\n");
  printf("> ");
  unsigned src, dest, i, j;
  while (scanf("%u%u%u%u", &src, &dest, &i, &j) == 4) {
    printf("Input:\n");
    printf("src =\t");
    print_binary(src);
    printf("dest =\t");
    print_binary(dest);
    printf("Result:\n");
    unsigned copied = copy_bits(src, dest, i, j);
    printf("dest =\t");
    print_binary(copied);
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
lea    0xed4(%rip),%rdi
call   1040 <printf@plt>
lea    0xf05(%rip),%rdi
call   1040 <printf@plt>
lea    0xefc(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1060 <scanf@plt>
cmp    $0x4,%eax
jne    1211 <main+0xd1>
lea    0xee0(%rip),%rdi
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <print_binary@plt>
lea    0xecf(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <print_binary@plt>
lea    0xec3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <copy_bits@plt>
mov    %eax,-0x18(%rbp)
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1050 <print_binary@plt>
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
jmp    1173 <main+0x33>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
lea    0xedf(%rip),%rdi
call   1040 <puts@plt>
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
call   1070 <scanf@plt>
cmp    $0x4,%eax
jne    1261 <main+0x111>
lea    0xe61(%rip),%rbx
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
call   1060 <print_binary@plt>
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
call   1060 <print_binary@plt>
lea    0xe8a(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
call   1030 <copy_bits@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1060 <print_binary@plt>
lea    0xdc5(%rip),%rdi
call   1050 <printf@plt>
lea    0xdbc(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1070 <scanf@plt>
cmp    $0x4,%eax
je     11d0 <main+0x80>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"Enter source number, target number, and indexes i, j\0A\00"
@.str.1 = [61 x i8] c"This will copy the bits in `source[i..j]` to `target[i..j]`\0A\00"
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [9 x i8] c"%u%u%u%u\00"
@.str.4 = [8 x i8] c"Input:\0A\00"
@.str.5 = [7 x i8] c"src =\09\00"
@.str.6 = [8 x i8] c"dest =\09\00"
@.str.7 = [9 x i8] c"Result:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %13, %0
%11 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5)
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %31
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%16 = load i32, i32* %2
%17 = call i32 @print_binary(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%19 = load i32, i32* %3
%20 = call i32 @print_binary(i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = call i32 @copy_bits(i32 %22, i32 %23, i32 %24, i32 %25)
store i32 %26, i32* %6
%27 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%28 = load i32, i32* %6
%29 = call i32 @print_binary(i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %10
31: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [9 x i8] c"%u%u%u%u\00"
@.str.5 = [7 x i8] c"src =\09\00"
@.str.6 = [8 x i8] c"dest =\09\00"
@str = [53 x i8] c"Enter source number, target number, and indexes i, j\00"
@str.8 = [60 x i8] c"This will copy the bits in `source[i..j]` to `target[i..j]`\00"
@str.9 = [7 x i8] c"Input:\00"
@str.10 = [8 x i8] c"Result:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.8, i64 0, i64 0))
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4)
%13 = icmp eq i32 %12, 4
br i1 %13, label %14, label %33
14: ; preds = %0, %14
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.9, i64 0, i64 0))
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%17 = load i32, i32* %1
%18 = call i32 @print_binary(i32 %17)
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%20 = load i32, i32* %2
%21 = call i32 @print_binary(i32 %20)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0))
%23 = load i32, i32* %1
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = call i32 @copy_bits(i32 %23, i32 %24, i32 %25, i32 %26)
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%29 = call i32 @print_binary(i32 %27)
%30 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4)
%32 = icmp eq i32 %31, 4
br i1 %32, label %14, label %33
33: ; preds = %14, %0
ret i32 0
}