#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 main() {
  int a = -2147483648;
  int b = -1;
  long long a1 = (long long)a;
  long long b1 = (long long)b;
  long long res = 0;
  int len = sizeof(int) * 8;
  int tmp = 1;
  int step = 0;
  tmp <<= len - 2;
  if (a < 0)
    a1 = 0 - a1;
  if (b < 0)
    b1 = 0 - b1;
  if (b1 == 1) {
    res = a1;
    printf("pre res=%ld\n", res);
    if (a < 0)
      printf("a<0,");
    if (b < 0)
      printf("b<0\n");
    if (((a >= 0) && (b < 0)) || ((a < 0) && (b >= 0)))
      res = 0 - res;
    printf("res= %ld\n", res);
    return res;
  }
  while (a1 >= b1) {
    step = -1;
    tmp = b1;
    while (a1 >= tmp) {
      tmp <<= 1;
      step++;
    }
    a1 -= tmp >> 1;
    res += 1 << step;
  }
  if ((a > 0) != (b > 0)) {
    res = 0 - res;
  }
  printf("res= %ld\n", res);
  return res;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x80000000,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movslq -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x20,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x2c(%rbp),%ecx
sub    $0x2,%ecx
mov    -0x30(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    117c <main+0x6c>
xor    %eax,%eax
sub    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1190 <main+0x80>
xor    %eax,%eax
sub    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x1,-0x20(%rbp)
jne    1235 <main+0x125>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    11cd <main+0xbd>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11e5 <main+0xd5>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jl     11f9 <main+0xe9>
cmpl   $0x0,-0xc(%rbp)
jl     120d <main+0xfd>
cmpl   $0x0,-0x8(%rbp)
jge    1217 <main+0x107>
cmpl   $0x0,-0xc(%rbp)
jl     1217 <main+0x107>
xor    %eax,%eax
sub    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    12ef <main+0x1df>
jmp    123a <main+0x12a>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jl     12ab <main+0x19b>
movl   $0xffffffff,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
cmp    %rcx,%rax
jl     127e <main+0x16e>
mov    -0x30(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1256 <main+0x146>
mov    -0x30(%rbp),%eax
sar    $0x1,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x34(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    123a <main+0x12a>
cmpl   $0x0,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x0,-0xc(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
je     12d6 <main+0x1c6>
xor    %eax,%eax
sub    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
mov    $0x80000000,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rdi
mov    $0x80000000,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x80000000,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"pre res=%ld\0A\00"
@.str.1 = [5 x i8] c"a<0,\00"
@.str.2 = [5 x i8] c"b<0\0A\00"
@.str.3 = [10 x i8] c"res= %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 -2147483648, i32* %2
store i32 -1, i32* %3
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
store i64 %11, i64* %4
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
store i64 %13, i64* %5
store i64 0, i64* %6
store i32 32, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 2
%16 = load i32, i32* %8
%17 = shl i32 %16, %15
store i32 %17, i32* %8
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %0
%21 = load i64, i64* %4
%22 = sub nsw i64 0, %21
store i64 %22, i64* %4
br label %23
23: ; preds = %20, %0
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i64, i64* %5
%28 = sub nsw i64 0, %27
store i64 %28, i64* %5
br label %29
29: ; preds = %26, %23
%30 = load i64, i64* %5
%31 = icmp eq i64 %30, 1
br i1 %31, label %32, label %65
32: ; preds = %29
%33 = load i64, i64* %4
store i64 %33, i64* %6
%34 = load i64, i64* %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %34)
%36 = load i32, i32* %2
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %32
%41 = load i32, i32* %3
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = load i32, i32* %2
%47 = icmp sge i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* %3
%50 = icmp slt i32 %49, 0
br i1 %50, label %57, label %51
51: ; preds = %48, %45
%52 = load i32, i32* %2
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %51
%55 = load i32, i32* %3
%56 = icmp sge i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %54, %48
%58 = load i64, i64* %6
%59 = sub nsw i64 0, %58
store i64 %59, i64* %6
br label %60
60: ; preds = %57, %54, %51
%61 = load i64, i64* %6
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 %61)
%63 = load i64, i64* %6
%64 = trunc i64 %63 to i32
store i32 %64, i32* %1
br label %110
65: ; preds = %29
br label %66
66: ; preds = %83, %65
%67 = load i64, i64* %4
%68 = load i64, i64* %5
%69 = icmp sge i64 %67, %68
br i1 %69, label %70, label %94
70: ; preds = %66
store i32 -1, i32* %9
%71 = load i64, i64* %5
%72 = trunc i64 %71 to i32
store i32 %72, i32* %8
br label %73
73: ; preds = %78, %70
%74 = load i64, i64* %4
%75 = load i32, i32* %8
%76 = sext i32 %75 to i64
%77 = icmp sge i64 %74, %76
br i1 %77, label %78, label %83
78: ; preds = %73
%79 = load i32, i32* %8
%80 = shl i32 %79, 1
store i32 %80, i32* %8
%81 = load i32, i32* %9
%82 = add nsw i32 %81, 1
store i32 %82, i32* %9
br label %73
83: ; preds = %73
%84 = load i32, i32* %8
%85 = ashr i32 %84, 1
%86 = sext i32 %85 to i64
%87 = load i64, i64* %4
%88 = sub nsw i64 %87, %86
store i64 %88, i64* %4
%89 = load i32, i32* %9
%90 = shl i32 1, %89
%91 = sext i32 %90 to i64
%92 = load i64, i64* %6
%93 = add nsw i64 %92, %91
store i64 %93, i64* %6
br label %66
94: ; preds = %66
%95 = load i32, i32* %2
%96 = icmp sgt i32 %95, 0
%97 = zext i1 %96 to i32
%98 = load i32, i32* %3
%99 = icmp sgt i32 %98, 0
%100 = zext i1 %99 to i32
%101 = icmp ne i32 %97, %100
br i1 %101, label %102, label %105
102: ; preds = %94
%103 = load i64, i64* %6
%104 = sub nsw i64 0, %103
store i64 %104, i64* %6
br label %105
105: ; preds = %102, %94
%106 = load i64, i64* %6
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 %106)
%108 = load i64, i64* %6
%109 = trunc i64 %108 to i32
store i32 %109, i32* %1
br label %110
110: ; preds = %105, %60
%111 = load i32, i32* %1
ret i32 %111
}

LLVM IR (-O2):
@.str = [13 x i8] c"pre res=%ld\0A\00"
@.str.1 = [5 x i8] c"a<0,\00"
@.str.3 = [10 x i8] c"res= %ld\0A\00"
@str = [4 x i8] c"b<0\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 2147483648)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 2147483648)
ret i32 -2147483648
}