#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 atoi(char *);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char *c;
  unsigned int x, y, sum, carry;
  printf("Enter x:");
  while ((*c = getchar()) < '0' && (*c = getchar()) > '9')
    ;
  x = atoi(c);
  printf("Enter y:");
  while ((*c = getchar()) < '0' && (*c = getchar()) > '9')
    ;
  y = atoi(c);
  printf("\nx = [%d]\n", x);
  printf("y = [%d]\n", y);
  sum = x ^ y;
  carry = x & y;
  while (carry != 0) {
    carry = carry << 1;
    x = sum;
    y = carry;
    sum = x ^ y;
    carry = x & y;
  }
  printf("\nx + y = [%d]\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x10(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x21(%rbp)
jge    1184 <main+0x54>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x10(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x39,%eax
setg   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1194 <main+0x64>
jmp    1199 <main+0x69>
jmp    114d <main+0x1d>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x10(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x22(%rbp)
jge    11ea <main+0xba>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x10(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x39,%eax
setg   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11fa <main+0xca>
jmp    11ff <main+0xcf>
jmp    11b3 <main+0x83>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
xor    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1275 <main+0x145>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
xor    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    123f <main+0x10f>
mov    -0x1c(%rbp),%esi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"Enter x:\00"
@.str.1 = [9 x i8] c"Enter y:\00"
@.str.2 = [11 x i8] c"\0Ax = [%d]\0A\00"
@.str.3 = [10 x i8] c"y = [%d]\0A\00"
@.str.4 = [15 x i8] c"\0Ax + y = [%d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %20, %0
%9 = call signext i8 (...) @getchar()
%10 = load i8*, i8** %2
store i8 %9, i8* %10
%11 = sext i8 %9 to i32
%12 = icmp slt i32 %11, 48
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = call signext i8 (...) @getchar()
%15 = load i8*, i8** %2
store i8 %14, i8* %15
%16 = sext i8 %14 to i32
%17 = icmp sgt i32 %16, 57
br label %18
18: ; preds = %13, %8
%19 = phi i1 [ false, %8 ], [ %17, %13 ]
br i1 %19, label %20, label %21
20: ; preds = %18
br label %8
21: ; preds = %18
%22 = load i8*, i8** %2
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %37, %21
%26 = call signext i8 (...) @getchar()
%27 = load i8*, i8** %2
store i8 %26, i8* %27
%28 = sext i8 %26 to i32
%29 = icmp slt i32 %28, 48
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = call signext i8 (...) @getchar()
%32 = load i8*, i8** %2
store i8 %31, i8* %32
%33 = sext i8 %31 to i32
%34 = icmp sgt i32 %33, 57
br label %35
35: ; preds = %30, %25
%36 = phi i1 [ false, %25 ], [ %34, %30 ]
br i1 %36, label %37, label %38
37: ; preds = %35
br label %25
38: ; preds = %35
%39 = load i8*, i8** %2
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %4
%41 = load i32, i32* %3
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %4
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %3
%46 = load i32, i32* %4
%47 = xor i32 %45, %46
store i32 %47, i32* %5
%48 = load i32, i32* %3
%49 = load i32, i32* %4
%50 = and i32 %48, %49
store i32 %50, i32* %6
br label %51
51: ; preds = %54, %38
%52 = load i32, i32* %6
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %65
54: ; preds = %51
%55 = load i32, i32* %6
%56 = shl i32 %55, 1
store i32 %56, i32* %6
%57 = load i32, i32* %5
store i32 %57, i32* %3
%58 = load i32, i32* %6
store i32 %58, i32* %4
%59 = load i32, i32* %3
%60 = load i32, i32* %4
%61 = xor i32 %59, %60
store i32 %61, i32* %5
%62 = load i32, i32* %3
%63 = load i32, i32* %4
%64 = and i32 %62, %63
store i32 %64, i32* %6
br label %51
65: ; preds = %51
%66 = load i32, i32* %5
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"Enter x:\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call signext i8 (...) @getchar()
unreachable
}