#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*/ booth(int, int);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printbin(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int string_handler(char *);
int main() {
  printf("Start of program:\n\n");
  char strMultiplier[20], strMultiplicand[20];
  int multiplier, multiplicand;
  while (1) {
    printf("\nEnter multiplier:   ");
    gets(strMultiplier);
    multiplier = string_handler(strMultiplier);
    printf("Enter multiplicand: ");
    gets(strMultiplicand);
    multiplicand = string_handler(strMultiplicand);
    if (multiplicand != -1 && multiplier != -1)
      break;
  }
  printf(
      "\n================================================================\n");
  printf("Multiplying:   %d X %d\n", multiplicand, multiplier);
  printf("Multiplicand: ");
  printbin(multiplicand, 0, 32);
  printf("\nMultiplier:   ");
  printbin(multiplier, 0, 32);
  printf("\n================================================================="
         "\n\n\n\n");
  booth(multiplier, multiplicand);
  printf("\n\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1070 <gets@plt>
lea    -0x20(%rbp),%rdi
call   1040 <string_handler@plt>
mov    %eax,-0x44(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1070 <gets@plt>
lea    -0x40(%rbp),%rdi
call   1040 <string_handler@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
je     11cc <main+0x7c>
cmpl   $0xffffffff,-0x44(%rbp)
je     11cc <main+0x7c>
jmp    11d1 <main+0x81>
jmp    116d <main+0x1d>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <printbin@plt>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <printbin@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%edi
mov    -0x48(%rbp),%esi
call   1050 <booth@plt>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%r14
lea    0x20(%rsp),%r15
lea    0xe89(%rip),%r12
mov    %rsp,%r13
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1080 <gets@plt>
mov    %r15,%rdi
call   1050 <string_handler@plt>
mov    %eax,%ebx
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
call   1080 <gets@plt>
mov    %r13,%rdi
call   1050 <string_handler@plt>
cmp    $0xffffffff,%eax
je     1190 <main+0x30>
cmp    $0xffffffff,%ebx
je     1190 <main+0x30>
mov    %eax,%ebp
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe46(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <printbin@plt>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <printbin@plt>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1060 <booth@plt>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Start of program:\0A\0A\00"
@.str.1 = [22 x i8] c"\0AEnter multiplier: \00"
@.str.2 = [21 x i8] c"Enter multiplicand: \00"
@.str.3 = [67 x i8] c"\0A================================================================\0A\00"
@.str.4 = [24 x i8] c"Multiplying: %d X %d\0A\00"
@.str.5 = [15 x i8] c"Multiplicand: \00"
@.str.6 = [16 x i8] c"\0AMultiplier: \00"
@.str.7 = [71 x i8] c"\0A=================================================================\0A\0A\0A\0A\00"
@.str.8 = [4 x i8] c"\0A\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [20 x i8]
%4 = alloca i32
%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))
br label %7
7: ; preds = %0, %24
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%10 = call i32 @gets(i8* %9)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%12 = call i32 @string_handler(i8* %11)
store i32 %12, i32* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%15 = call i32 @gets(i8* %14)
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%17 = call i32 @string_handler(i8* %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %7
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %20
br label %25
24: ; preds = %20, %7
br label %7
25: ; preds = %23
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* %5
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* %5
%32 = call i32 @printbin(i32 %31, i32 0, i32 32)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%34 = load i32, i32* %4
%35 = call i32 @printbin(i32 %34, i32 0, i32 32)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.7, i64 0, i64 0))
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = call i32 @booth(i32 %37, i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"\0AEnter multiplier: \00"
@.str.2 = [21 x i8] c"Enter multiplicand: \00"
@.str.4 = [24 x i8] c"Multiplying: %d X %d\0A\00"
@.str.5 = [15 x i8] c"Multiplicand: \00"
@.str.6 = [16 x i8] c"\0AMultiplier: \00"
@str = [19 x i8] c"Start of program:\0A\00"
@str.9 = [66 x i8] c"\0A================================================================\00"
@str.10 = [70 x i8] c"\0A=================================================================\0A\0A\0A\00"
@str.11 = [3 x i8] c"\0A\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [20 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
br label %6
6: ; preds = %6, %0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @gets(i8* %4)
%9 = call i32 @string_handler(i8* %4)
%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 @gets(i8* %5)
%12 = call i32 @string_handler(i8* %5)
%13 = icmp ne i32 %12, -1
%14 = icmp ne i32 %9, -1
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.9, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %12, i32 %9)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 @printbin(i32 %12, i32 0, i32 32)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%22 = call i32 @printbin(i32 %9, i32 0, i32 32)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.10, i64 0, i64 0))
%24 = call i32 @booth(i32 %9, i32 %12)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.11, i64 0, i64 0))
ret i32 0
}