#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 /*<<< orphan*/ scanf(char *, int *, int *);
int main() {
  while (1) {
    int h, t;
    scanf("%d %d", &h, &t);
    if (!h && !t)
      break;
    printf("%d\n", ((h % 2) * 2 + (t % 4) * 3) % 4 +
                       (t + ((h % 2) * 2 + (t % 4) * 3) % 4) / 2 +
                       (h + (t + ((h % 2) * 2 + (t % 4) * 3) % 4) / 2) / 2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    115c <main+0x3c>
cmpl   $0x0,-0xc(%rbp)
jne    115c <main+0x3c>
jmp    1232 <main+0x112>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
shl    $0x1,%edx
mov    %edx,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x24(%rbp),%eax
imul   $0x3,%edx,%ecx
add    %ecx,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
shl    $0x1,%edx
mov    %edx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
imul   $0x3,%edx,%ecx
add    %ecx,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
add    %edx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    %eax,%esi
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
shl    $0x1,%edx
mov    %edx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%eax
imul   $0x3,%edx,%ecx
add    %ecx,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x14(%rbp),%eax
add    %edx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    %eax,%esi
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
mov    (%rsp),%ecx
mov    %eax,%edx
or     %ecx,%edx
je     11e3 <main+0xc3>
lea    0xeb2(%rip),%r14
lea    0xea5(%rip),%r15
lea    0x4(%rsp),%r12
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
and    $0x7ffffffe,%edx
mov    %eax,%esi
sub    %edx,%esi
lea    0x3(%rcx),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xfffffffc,%edx
mov    %ecx,%edi
sub    %edx,%edi
lea    (%rdi,%rdi,2),%edx
lea    (%rdx,%rsi,2),%edi
lea    (%rdx,%rsi,2),%edx
add    $0x3,%edx
test   %edi,%edi
cmovns %edi,%edx
and    $0xfffffffc,%edx
sub    %edx,%edi
add    %edi,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
add    %edx,%edi
add    %eax,%edx
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
sar    %esi
add    %edi,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
mov    (%rsp),%ecx
mov    %eax,%edx
or     %ecx,%edx
jne    1170 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %0, %12
%5 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %8
br label %49
12: ; preds = %8, %4
%13 = load i32, i32* %2
%14 = srem i32 %13, 2
%15 = mul nsw i32 %14, 2
%16 = load i32, i32* %3
%17 = srem i32 %16, 4
%18 = mul nsw i32 %17, 3
%19 = add nsw i32 %15, %18
%20 = srem i32 %19, 4
%21 = load i32, i32* %3
%22 = load i32, i32* %2
%23 = srem i32 %22, 2
%24 = mul nsw i32 %23, 2
%25 = load i32, i32* %3
%26 = srem i32 %25, 4
%27 = mul nsw i32 %26, 3
%28 = add nsw i32 %24, %27
%29 = srem i32 %28, 4
%30 = add nsw i32 %21, %29
%31 = sdiv i32 %30, 2
%32 = add nsw i32 %20, %31
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = load i32, i32* %2
%36 = srem i32 %35, 2
%37 = mul nsw i32 %36, 2
%38 = load i32, i32* %3
%39 = srem i32 %38, 4
%40 = mul nsw i32 %39, 3
%41 = add nsw i32 %37, %40
%42 = srem i32 %41, 4
%43 = add nsw i32 %34, %42
%44 = sdiv i32 %43, 2
%45 = add nsw i32 %33, %44
%46 = sdiv i32 %45, 2
%47 = add nsw i32 %32, %46
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %4
49: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = icmp ne i32 %6, 0
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %33
11: ; preds = %0, %11
%12 = phi i32 [ %30, %11 ], [ %8, %0 ]
%13 = phi i32 [ %28, %11 ], [ %6, %0 ]
%14 = srem i32 %13, 2
%15 = shl nsw i32 %14, 1
%16 = srem i32 %12, 4
%17 = mul nsw i32 %16, 3
%18 = add nsw i32 %17, %15
%19 = srem i32 %18, 4
%20 = add nsw i32 %19, %12
%21 = sdiv i32 %20, 2
%22 = add nsw i32 %21, %19
%23 = add nsw i32 %21, %13
%24 = sdiv i32 %23, 2
%25 = add nsw i32 %22, %24
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%28 = load i32, i32* %1
%29 = icmp ne i32 %28, 0
%30 = load i32, i32* %2
%31 = icmp ne i32 %30, 0
%32 = select i1 %29, i1 true, i1 %31
br i1 %32, label %11, label %33
33: ; preds = %11, %0
ret i32 0
}