#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 bitAt(unsigned int, unsigned int);
int /*<<< orphan*/ increment(unsigned int *);
int /*<<< orphan*/ setBit(unsigned int, unsigned int *, unsigned int);
unsigned int add(unsigned int x, unsigned int y, int *c) {
  unsigned int ans = 0, final = 0, k = 1;
  unsigned int a, b;
  while (k < 31) {
    a = bitAt(k, x);
    b = bitAt(k, y);
    ans = *c ^ (a ^ b);
    setBit(k, &final, ans);
    *c = (a & b) | (a & (*c)) | (b & (*c));
    increment(&k);
  }
  return final;
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x1f,-0x1c(%rbp)
jae    11cd <add+0x9d>
mov    -0x1c(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <bitAt@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <bitAt@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%ecx
xor    -0x24(%rbp),%ecx
xor    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1050 <setBit@plt>
mov    -0x20(%rbp),%ecx
and    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%rdx
and    (%rdx),%eax
or     %eax,%ecx
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rdx
and    (%rdx),%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x1c(%rbp),%rdi
call   1030 <increment@plt>
jmp    1157 <add+0x27>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%r13d
movl   $0x0,0x4(%rsp)
movl   $0x1,(%rsp)
mov    $0x1,%edi
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    %r13d,%esi
call   1040 <bitAt@plt>
mov    %eax,%ebp
mov    (%rsp),%edi
mov    %r14d,%esi
call   1040 <bitAt@plt>
mov    %eax,%r15d
mov    %eax,%edx
xor    %ebp,%edx
xor    (%rbx),%edx
mov    (%rsp),%edi
lea    0x4(%rsp),%rsi
call   1050 <setBit@plt>
mov    (%rbx),%eax
mov    %eax,%ecx
or     %r15d,%ecx
and    %ebp,%ecx
and    %r15d,%eax
or     %ecx,%eax
mov    %eax,(%rbx)
mov    %r12,%rdi
call   1030 <increment@plt>
mov    (%rsp),%edi
cmp    $0x1f,%edi
jb     1160 <add+0x30>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @add(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
br label %12
12: ; preds = %15, %3
%13 = load i32, i32* %9
%14 = icmp ult i32 %13, 31
br i1 %14, label %15, label %46
15: ; preds = %12
%16 = load i32, i32* %9
%17 = load i32, i32* %4
%18 = call i32 @bitAt(i32 %16, i32 %17)
store i32 %18, i32* %10
%19 = load i32, i32* %9
%20 = load i32, i32* %5
%21 = call i32 @bitAt(i32 %19, i32 %20)
store i32 %21, i32* %11
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = load i32, i32* %10
%25 = load i32, i32* %11
%26 = xor i32 %24, %25
%27 = xor i32 %23, %26
store i32 %27, i32* %7
%28 = load i32, i32* %9
%29 = load i32, i32* %7
%30 = call i32 @setBit(i32 %28, i32* %8, i32 %29)
%31 = load i32, i32* %10
%32 = load i32, i32* %11
%33 = and i32 %31, %32
%34 = load i32, i32* %10
%35 = load i32*, i32** %6
%36 = load i32, i32* %35
%37 = and i32 %34, %36
%38 = or i32 %33, %37
%39 = load i32, i32* %11
%40 = load i32*, i32** %6
%41 = load i32, i32* %40
%42 = and i32 %39, %41
%43 = or i32 %38, %42
%44 = load i32*, i32** %6
store i32 %43, i32* %44
%45 = call i32 @increment(i32* %9)
br label %12
46: ; preds = %12
%47 = load i32, i32* %8
ret i32 %47
}

LLVM IR (-O2):
define i32 @add(i32 %0, i32 %1, i32* nocapture %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = bitcast i32* %5 to i8*
store i32 1, i32* %5
br label %8
8: ; preds = %3, %8
%9 = phi i32 [ 1, %3 ], [ %24, %8 ]
%10 = call i32 @bitAt(i32 %9, i32 %0)
%11 = load i32, i32* %5
%12 = call i32 @bitAt(i32 %11, i32 %1)
%13 = load i32, i32* %2
%14 = xor i32 %12, %10
%15 = xor i32 %14, %13
%16 = load i32, i32* %5
%17 = call i32 @setBit(i32 %16, i32* %4, i32 %15)
%18 = load i32, i32* %2
%19 = or i32 %18, %12
%20 = and i32 %19, %10
%21 = and i32 %18, %12
%22 = or i32 %20, %21
store i32 %22, i32* %2
%23 = call i32 @increment(i32* %5)
%24 = load i32, i32* %5
%25 = icmp ult i32 %24, 31
br i1 %25, label %8, label %26
26: ; preds = %8
%27 = load i32, i32* %4
ret i32 %27
}