#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, int);
int main(void) {
  int n = 4096;
  int d = 10;
  int q = 0;
  int r = 0;
  int i = 32768;
  while (0 < i) {
    r <<= 1;
    if (n & i) {
      r |= 1;
    }
    if (d <= r) {
      r -= d;
      q |= i;
    }
    i >>= 1;
  }
  printf("Q=%d, R=%d\n", q, r);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1000,-0x8(%rbp)
movl   $0xa,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x8000,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jge    119c <main+0x8c>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    -0x18(%rbp),%eax
cmp    $0x0,%eax
je     116e <main+0x5e>
mov    -0x14(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     118e <main+0x7e>
mov    -0xc(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1142 <main+0x32>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x199,%esi
mov    $0x6,%edx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Q=%d, R=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 4096, i32* %2
store i32 10, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 32768, i32* %6
br label %7
7: ; preds = %31, %0
%8 = load i32, i32* %6
%9 = icmp slt i32 0, %8
br i1 %9, label %10, label %34
10: ; preds = %7
%11 = load i32, i32* %5
%12 = shl i32 %11, 1
store i32 %12, i32* %5
%13 = load i32, i32* %2
%14 = load i32, i32* %6
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i32, i32* %5
%19 = or i32 %18, 1
store i32 %19, i32* %5
br label %20
20: ; preds = %17, %10
%21 = load i32, i32* %3
%22 = load i32, i32* %5
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i32, i32* %3
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, %25
store i32 %27, i32* %5
%28 = load i32, i32* %6
%29 = load i32, i32* %4
%30 = or i32 %29, %28
store i32 %30, i32* %4
br label %31
31: ; preds = %24, %20
%32 = load i32, i32* %6
%33 = ashr i32 %32, 1
store i32 %33, i32* %6
br label %7
34: ; preds = %7
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Q=%d, R=%d\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 409, i32 6)
ret i32 0
}