#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n1 = 0, n2 = 0, somma, riporto;
  int max_bit, i = 0;
  printf("Somma di due numeri binari");
  printf("\nInserisci numero di bit: ");
  scanf("%d", &max_bit);
  do {
    printf("\nInserisci bit del primo numero (da destra verso sinistra): ");
    scanf("%d", &n1);
    printf("Inserisci bit del secondo numero (da destra verso sinistra): ");
    scanf("%d", &n2);
    if ((n1 == 0 || n1 == 1) && (n2 == 0 || n2 == 1)) {
      i++;
      somma = n1 + n2 + riporto;
      if (somma-- >= 0) {
        riporto = somma--;
      }
      if (riporto) {
        somma = 1;
      }
      printf("%d", somma);
    } else {
      printf("\nNumero non valido. Riprova!");
    }
  } while (i < max_bit);
  if (riporto > 0) {
    printf("\nAttenzione! L'operazione è finita in OVERFLOW con riporto di %d.",
           riporto);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe93(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11c0 <main+0xa0>
cmpl   $0x1,-0x8(%rbp)
jne    1232 <main+0x112>
cmpl   $0x0,-0xc(%rbp)
je     11d4 <main+0xb4>
cmpl   $0x1,-0xc(%rbp)
jne    1232 <main+0x112>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
jl     120b <main+0xeb>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     121c <main+0xfc>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <main+0x120>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1245 <main+0x125>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1170 <main+0x50>
cmpl   $0x0,-0x14(%rbp)
jle    126c <main+0x14c>
mov    -0x14(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%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
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed5(%rip),%rbx
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0x10(%rsp),%r15
lea    0xefc(%rip),%r12
lea    0xc(%rsp),%r13
xor    %r14d,%r14d
jmp    11a5 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xf1d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    0x14(%rsp),%r14d
jge    1218 <main+0xf8>
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <scanf@plt>
mov    0x10(%rsp),%eax
cmp    $0x1,%eax
ja     1190 <main+0x70>
mov    0xc(%rsp),%ecx
cmp    $0x1,%ecx
ja     1190 <main+0x70>
add    $0x1,%r14d
add    %ebp,%eax
mov    %eax,%edx
add    %ecx,%edx
lea    -0x1(%rcx,%rax,1),%edx
lea    -0x2(%rcx,%rax,1),%esi
cmovs  %edx,%esi
cmovns %edx,%ebp
test   %ebp,%ebp
mov    $0x1,%eax
cmovne %eax,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    0x14(%rsp),%r14d
jl     11a5 <main+0x85>
test   %ebp,%ebp
jle    122c <main+0x10c>
lea    0xeae(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Somma di due numeri binari\00"
@.str.1 = [27 x i8] c"\0AInserisci numero di bit: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [61 x i8] c"\0AInserisci bit del primo numero (da destra verso sinistra): \00"
@.str.4 = [62 x i8] c"Inserisci bit del secondo numero (da destra verso sinistra): \00"
@.str.5 = [29 x i8] c"\0ANumero non valido. Riprova!\00"
@.str.6 = [67 x i8] c"\0AAttenzione! L'operazione \C3\A8 finita in OVERFLOW con riporto di %d.\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
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
br label %11
11: ; preds = %51, %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %11
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %48
21: ; preds = %18, %11
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %48
27: ; preds = %24, %21
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = add nsw i32 %30, %31
%33 = load i32, i32* %5
%34 = add nsw i32 %32, %33
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = add nsw i32 %35, -1
store i32 %36, i32* %4
%37 = icmp sge i32 %35, 0
br i1 %37, label %38, label %41
38: ; preds = %27
%39 = load i32, i32* %4
%40 = add nsw i32 %39, -1
store i32 %40, i32* %4
store i32 %39, i32* %5
br label %41
41: ; preds = %38, %27
%42 = load i32, i32* %5
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 1, i32* %4
br label %45
45: ; preds = %44, %41
%46 = load i32, i32* %4
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %50
48: ; preds = %24, %18
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = load i32, i32* %6
%54 = icmp slt i32 %52, %53
br i1 %54, label %11, label %55
55: ; preds = %51
%56 = load i32, i32* %5
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %5
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.6, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %58, %55
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@.str = [27 x i8] c"Somma di due numeri binari\00"
@.str.1 = [27 x i8] c"\0AInserisci numero di bit: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [61 x i8] c"\0AInserisci bit del primo numero (da destra verso sinistra): \00"
@.str.4 = [62 x i8] c"Inserisci bit del secondo numero (da destra verso sinistra): \00"
@.str.5 = [29 x i8] c"\0ANumero non valido. Riprova!\00"
@.str.6 = [67 x i8] c"\0AAttenzione! L'operazione \C3\A8 finita in OVERFLOW con riporto di %d.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
br label %10
10: ; preds = %36, %0
%11 = phi i32 [ undef, %0 ], [ %37, %36 ]
%12 = phi i32 [ 0, %0 ], [ %38, %36 ]
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %1
%18 = icmp ult i32 %17, 2
br i1 %18, label %19, label %34
19: ; preds = %10
%20 = load i32, i32* %2
%21 = icmp ult i32 %20, 2
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = add nsw i32 %12, 1
%24 = add i32 %17, %11
%25 = add i32 %24, %20
%26 = add nsw i32 %25, -1
%27 = icmp sgt i32 %25, -1
%28 = add nsw i32 %25, -2
%29 = select i1 %27, i32 %28, i32 %26
%30 = select i1 %27, i32 %26, i32 %11
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i32 %29, i32 1
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %36
34: ; preds = %19, %10
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %36
36: ; preds = %22, %34
%37 = phi i32 [ %30, %22 ], [ %11, %34 ]
%38 = phi i32 [ %23, %22 ], [ %12, %34 ]
%39 = load i32, i32* %3
%40 = icmp slt i32 %38, %39
br i1 %40, label %10, label %41
41: ; preds = %36
%42 = icmp sgt i32 %37, 0
br i1 %42, label %43, label %45
43: ; preds = %41
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.6, i64 0, i64 0), i32 %37)
br label %45
45: ; preds = %43, %41
ret i32 0
}