#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 MUX16way(int /*<<< orphan*/, int, int, int, int, int, int, int, int, int,
             int, int, int, int, int, int, int);
int MUX2way(int, int, int);
int /*<<< orphan*/ bin32(int);
int /*<<< orphan*/ header_print(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int A, B, selec, i;
  int output;
  A = 31;
  B = 20;
  bin32(A);
  bin32(B);
  header_print("TESTING 2-way Multiplexer");
  for (i = 0; i < 2; i++) {
    printf("---------------------------\nSelect bit: %d\n", i);
    output = MUX2way(A, B, i);
    printf("OUT=%d ; ", output);
    bin32(output);
  }
  header_print("Testing 16-way Multiplexer");
  for (i = 0; i < 16; i++) {
    printf("---------------------------\nSelect command: %d\n", i);
    output = MUX16way(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, i);
    printf("OUT=%d\n ; ", output);
    bin32(output);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1f,-0x8(%rbp)
movl   $0x14,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <bin32@plt>
mov    -0xc(%rbp),%edi
call   1070 <bin32@plt>
lea    0xe7c(%rip),%rdi
call   1050 <header_print@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    11df <main+0x8f>
mov    -0x14(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <MUX2way@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1070 <bin32@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1190 <main+0x40>
lea    0xe6a(%rip),%rdi
call   1050 <header_print@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    12ab <main+0x15b>
mov    -0x14(%rbp),%esi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x3,%ecx
mov    $0x4,%r8d
mov    $0x5,%r9d
movl   $0x6,(%rsp)
movl   $0x7,0x8(%rsp)
movl   $0x8,0x10(%rsp)
movl   $0x9,0x18(%rsp)
movl   $0xa,0x20(%rsp)
movl   $0xb,0x28(%rsp)
movl   $0xc,0x30(%rsp)
movl   $0xd,0x38(%rsp)
movl   $0xe,0x40(%rsp)
movl   $0xf,0x48(%rsp)
mov    %eax,0x50(%rsp)
call   1060 <MUX16way@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1070 <bin32@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f2 <main+0xa2>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1f,%edi
call   1070 <bin32@plt>
mov    $0x14,%edi
call   1070 <bin32@plt>
lea    0xe8e(%rip),%rdi
call   1050 <header_print@plt>
lea    0xe9c(%rip),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    $0x1f,%edi
mov    $0x14,%esi
xor    %edx,%edx
call   1040 <MUX2way@plt>
mov    %eax,%ebp
lea    0xea2(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1070 <bin32@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    $0x1f,%edi
mov    $0x14,%esi
mov    $0x1,%edx
call   1040 <MUX2way@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1070 <bin32@plt>
lea    0xe60(%rip),%rdi
call   1050 <header_print@plt>
lea    0xe6f(%rip),%r14
lea    0xe98(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
sub    $0x8,%rsp
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x3,%ecx
mov    $0x4,%r8d
mov    $0x5,%r9d
push   %rbx
push   $0xf
push   $0xe
push   $0xd
push   $0xc
push   $0xb
push   $0xa
push   $0x9
push   $0x8
push   $0x7
push   $0x6
call   1060 <MUX16way@plt>
add    $0x60,%rsp
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1070 <bin32@plt>
add    $0x1,%ebx
cmp    $0x10,%ebx
jne    1210 <main+0xc0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"TESTING 2-way Multiplexer\00"
@.str.1 = [44 x i8] c"---------------------------\0ASelect bit: %d\0A\00"
@.str.2 = [10 x i8] c"OUT=%d ; \00"
@.str.3 = [27 x i8] c"Testing 16-way Multiplexer\00"
@.str.4 = [48 x i8] c"---------------------------\0ASelect command: %d\0A\00"
@.str.5 = [11 x i8] c"OUT=%d\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
store i32 31, i32* %2
store i32 20, i32* %3
%7 = load i32, i32* %2
%8 = call i32 @bin32(i32 %7)
%9 = load i32, i32* %3
%10 = call i32 @bin32(i32 %9)
%11 = call i32 @header_print(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %12
12: ; preds = %26, %0
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i32, i32* %5
%17 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = load i32, i32* %5
%21 = call i32 @MUX2way(i32 %18, i32 %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %6
%25 = call i32 @bin32(i32 %24)
br label %26
26: ; preds = %15
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %12
29: ; preds = %12
%30 = call i32 @header_print(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %31
31: ; preds = %43, %29
%32 = load i32, i32* %5
%33 = icmp slt i32 %32, 16
br i1 %33, label %34, label %46
34: ; preds = %31
%35 = load i32, i32* %5
%36 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %5
%38 = call i32 @MUX16way(i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 %37)
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %6
%42 = call i32 @bin32(i32 %41)
br label %43
43: ; preds = %34
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %31
46: ; preds = %31
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"TESTING 2-way Multiplexer\00"
@.str.1 = [44 x i8] c"---------------------------\0ASelect bit: %d\0A\00"
@.str.2 = [10 x i8] c"OUT=%d ; \00"
@.str.3 = [27 x i8] c"Testing 16-way Multiplexer\00"
@.str.4 = [48 x i8] c"---------------------------\0ASelect command: %d\0A\00"
@.str.5 = [11 x i8] c"OUT=%d\0A ; \00"
define i32 @main() {
%1 = tail call i32 @bin32(i32 31)
%2 = tail call i32 @bin32(i32 20)
%3 = tail call i32 @header_print(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 0)
%5 = tail call i32 @MUX2way(i32 31, i32 20, i32 0)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = tail call i32 @bin32(i32 %5)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 1)
%9 = tail call i32 @MUX2way(i32 31, i32 20, i32 1)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = tail call i32 @bin32(i32 %9)
%12 = tail call i32 @header_print(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %0, %13
%14 = phi i32 [ 0, %0 ], [ %19, %13 ]
%15 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = tail call i32 @MUX16way(i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 %14)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = tail call i32 @bin32(i32 %16)
%19 = add nuw nsw i32 %14, 1
%20 = icmp eq i32 %19, 16
br i1 %20, label %21, label %13
21: ; preds = %13
ret i32 0
}