#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*/ bin32(unsigned int);
unsigned int fullAdder32(unsigned int, unsigned int, int, int *);
int /*<<< orphan*/ header_print(char *);
int /*<<< orphan*/ line_print();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned int *, unsigned int *);
int main() {
  unsigned int A, B, res, target, overflow_bit;
  int *carryOut;
  printf("Enter values for register A and B: ");
  scanf("%d %d", &A, &B);
  target = A + B;
  overflow_bit = 0;
  int carryIn = 0;
  carryOut = &overflow_bit;
  header_print("Testing FULL ADDER 32-BITS");
  res = fullAdder32(A, B, carryIn, carryOut);
  if (res == target) {
    printf("SUCCESS!!\n");
    printf("Overflow bit: %d\n", overflow_bit);
    printf("%u + %u = %u; should be: %u\n", A, B, res, target);
    printf("%#08x + %#08x = %#08x; should be: %#08x\n", A, B, res, target);
    bin32(A);
    bin32(B);
    line_print();
    bin32(res);
  } else {
    printf("FAILED\n");
    printf("CarryOut: %d\n", *carryOut);
    printf("%u + %u = %u; should be: %u\n", A, B, res, target);
    printf("%#08x + %#08x = %#08x; should be: %#08x\n", A, B, res, target);
    bin32(res);
    printf("                  %s\n", "=/=");
    bin32(target);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea0(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe73(%rip),%rdi
call   1060 <header_print@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <fullAdder32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1256 <main+0xf6>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <bin32@plt>
mov    -0xc(%rbp),%edi
call   1080 <bin32@plt>
mov    $0x0,%al
call   1050 <line_print@plt>
mov    -0x10(%rbp),%edi
call   1080 <bin32@plt>
jmp    12d3 <main+0x173>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
call   1080 <bin32@plt>
lea    0xe01(%rip),%rdi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <bin32@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe99(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1080 <scanf@plt>
mov    0xc(%rsp),%ebx
add    0x10(%rsp),%ebx
movl   $0x0,0x14(%rsp)
lea    0xe79(%rip),%rdi
call   1070 <header_print@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
lea    0x14(%rsp),%rcx
xor    %edx,%edx
call   1040 <fullAdder32@plt>
cmp    %ebx,%eax
jne    123d <main+0xcd>
lea    0xef7(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%rsp),%esi
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe5c(%rip),%rdi
mov    %ebx,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe5e(%rip),%rdi
mov    %ebx,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%edi
call   1090 <bin32@plt>
mov    0xc(%rsp),%edi
call   1090 <bin32@plt>
xor    %eax,%eax
call   1060 <line_print@plt>
jmp    12af <main+0x13f>
mov    %eax,%ebp
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%rsp),%esi
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xdeb(%rip),%rdi
mov    %ebp,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xded(%rip),%rdi
mov    %ebp,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1090 <bin32@plt>
lea    0xe0a(%rip),%rdi
lea    0xe19(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1090 <bin32@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Enter values for register A and B: \00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [27 x i8] c"Testing FULL ADDER 32-BITS\00"
@.str.3 = [11 x i8] c"SUCCESS!!\0A\00"
@.str.4 = [18 x i8] c"Overflow bit: %d\0A\00"
@.str.5 = [29 x i8] c"%u + %u = %u; should be: %u\0A\00"
@.str.6 = [41 x i8] c"%x + %x = %x; should be: %x\0A\00"
@.str.7 = [8 x i8] c"FAILED\0A\00"
@.str.8 = [14 x i8] c"CarryOut: %d\0A\00"
@.str.9 = [22 x i8] c" %s\0A\00"
@.str.10 = [4 x i8] c"=/=\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*
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = add i32 %11, %12
store i32 %13, i32* %5
store i32 0, i32* %6
store i32 0, i32* %8
store i32* %6, i32** %7
%14 = call i32 @header_print(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = load i32, i32* %8
%18 = load i32*, i32** %7
%19 = call i32 @fullAdder32(i32 %15, i32 %16, i32 %17, i32* %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %44
23: ; preds = %0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = load i32, i32* %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %32, i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* %2
%38 = call i32 @bin32(i32 %37)
%39 = load i32, i32* %3
%40 = call i32 @bin32(i32 %39)
%41 = call i32 (...) @line_print()
%42 = load i32, i32* %4
%43 = call i32 @bin32(i32 %42)
br label %64
44: ; preds = %0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32*, i32** %7
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %2
%50 = load i32, i32* %3
%51 = load i32, i32* %4
%52 = load i32, i32* %5
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 %50, i32 %51, i32 %52)
%54 = load i32, i32* %2
%55 = load i32, i32* %3
%56 = load i32, i32* %4
%57 = load i32, i32* %5
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %54, i32 %55, i32 %56, i32 %57)
%59 = load i32, i32* %4
%60 = call i32 @bin32(i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%62 = load i32, i32* %5
%63 = call i32 @bin32(i32 %62)
br label %64
64: ; preds = %44, %23
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Enter values for register A and B: \00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [27 x i8] c"Testing FULL ADDER 32-BITS\00"
@.str.4 = [18 x i8] c"Overflow bit: %d\0A\00"
@.str.5 = [29 x i8] c"%u + %u = %u; should be: %u\0A\00"
@.str.6 = [41 x i8] c"%x + %x = %x; should be: %x\0A\00"
@.str.8 = [14 x i8] c"CarryOut: %d\0A\00"
@.str.9 = [22 x i8] c" %s\0A\00"
@.str.10 = [4 x i8] c"=/=\00"
@str = [7 x i8] c"FAILED\00"
@str.11 = [10 x i8] c"SUCCESS!!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = add i32 %10, %9
store i32 0, i32* %3
%12 = call i32 @header_print(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = call i32 @fullAdder32(i32 %13, i32 %14, i32 0, i32* %3)
%16 = icmp eq i32 %15, %11
br i1 %16, label %17, label %32
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.11, i64 0, i64 0))
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %1
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %21, i32 %22, i32 %11, i32 %11)
%24 = load i32, i32* %1
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %24, i32 %25, i32 %11, i32 %11)
%27 = load i32, i32* %1
%28 = call i32 @bin32(i32 %27)
%29 = load i32, i32* %2
%30 = call i32 @bin32(i32 %29)
%31 = call i32 (...) @line_print()
br label %44
32: ; preds = %0
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%34 = load i32, i32* %3
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %1
%37 = load i32, i32* %2
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %36, i32 %37, i32 %15, i32 %11)
%39 = load i32, i32* %1
%40 = load i32, i32* %2
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %39, i32 %40, i32 %15, i32 %11)
%42 = call i32 @bin32(i32 %15)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
br label %44
44: ; preds = %32, %17
%45 = call i32 @bin32(i32 %11)
ret i32 0
}