#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 EOF;
int /*<<< orphan*/ UINT_MAX;
int getchar();
scalar_t__ is_num(int);
scalar_t__ is_ws(int);
unsigned int l_m_bit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned int);
unsigned int rightrot(unsigned int, unsigned int);
int /*<<< orphan*/ showbits(unsigned int);
int main(void) {
  extern unsigned maxbit;
  maxbit = l_m_bit(UINT_MAX);
  int c, in_num = 0;
  unsigned bf = (1 << (maxbit / 2)) - 1, rot_num = 0;
  while ((c = getchar()) != EOF) {
    if (in_num && is_ws(c)) {
      printf("Old bit field:\n\t%u = ", bf);
      showbits(bf);
      bf = rightrot(bf, rot_num);
      printf("New bit field:\n\t%u = ", bf);
      showbits(bf);
      in_num = 0;
      rot_num = 0;
    } else if (!in_num && is_num(c)) {
      rot_num = c - '0';
      in_num = 1;
    } else if (in_num && is_num(c)) {
      rot_num = rot_num * 10 + c - '0';
    } else {
      in_num = 0;
      rot_num = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1070 <l_m_bit@plt>
mov    %eax,%ecx
mov    0x2e32(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0xc(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%ecx
shr    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%eax
je     12bf <main+0x14f>
cmpl   $0x0,-0xc(%rbp)
je     1243 <main+0xd3>
mov    -0x8(%rbp),%edi
call   1040 <is_ws@plt>
cmp    $0x0,%rax
je     1243 <main+0xd3>
mov    -0x10(%rbp),%esi
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%edi
call   1030 <showbits@plt>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1060 <rightrot@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xdf3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%edi
call   1030 <showbits@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    12ba <main+0x14a>
cmpl   $0x0,-0xc(%rbp)
jne    1274 <main+0x104>
mov    -0x8(%rbp),%edi
call   1090 <is_num@plt>
cmp    $0x0,%rax
je     1274 <main+0x104>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    12b5 <main+0x145>
cmpl   $0x0,-0xc(%rbp)
je     12a2 <main+0x132>
mov    -0x8(%rbp),%edi
call   1090 <is_num@plt>
cmp    $0x0,%rax
je     12a2 <main+0x132>
imul   $0xa,-0x14(%rbp),%eax
add    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    12b0 <main+0x140>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    12b5 <main+0x145>
jmp    12ba <main+0x14a>
jmp    11bf <main+0x4f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1070 <l_m_bit@plt>
mov    %eax,%r14d
mov    0x2e35(%rip),%rax
mov    %r14d,(%rax)
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0x2e3c(%rip),%r13
cmp    0x0(%r13),%eax
jne    11bb <main+0x4b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
shr    %r14d
mov    $0xffffffff,%ebp
mov    %r14d,%ecx
shl    %cl,%ebp
not    %ebp
lea    0xe43(%rip),%r15
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    120c <main+0x9c>
nopl   0x0(%rax,%rax,1)
call   1090 <is_num@plt>
add    $0xffffffd0,%ebx
xor    %r14d,%r14d
test   %rax,%rax
setne  %r14b
mov    $0x0,%eax
cmove  %eax,%ebx
mov    %ebx,%r12d
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%eax
je     11aa <main+0x3a>
mov    %ebx,%edi
test   %r14d,%r14d
je     11e0 <main+0x70>
call   1040 <is_ws@plt>
test   %rax,%rax
je     1260 <main+0xf0>
lea    0xddc(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1030 <showbits@plt>
mov    %ebp,%edi
mov    %r12d,%esi
call   1060 <rightrot@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1030 <showbits@plt>
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    11fd <main+0x8d>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1090 <is_num@plt>
test   %rax,%rax
je     124f <main+0xdf>
lea    (%r12,%r12,4),%eax
lea    (%rbx,%rax,2),%r12d
add    $0xffffffd0,%r12d
mov    $0x1,%r14d
jmp    11fd <main+0x8d>

LLVM IR (-O0):
@UINT_MAX = global i32 0
@maxbit = external global i32
@EOF = global i32 0
@.str = [22 x i8] c"Old bit field:\0A\09%u = \00"
@.str.1 = [22 x i8] c"New bit field:\0A\09%u = \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @UINT_MAX
%7 = call i32 @l_m_bit(i32 %6)
store i32 %7, i32* @maxbit
store i32 0, i32* %3
%8 = load i32, i32* @maxbit
%9 = udiv i32 %8, 2
%10 = shl i32 1, %9
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %4
store i32 0, i32* %5
br label %12
12: ; preds = %61, %0
%13 = call i32 (...) @getchar()
store i32 %13, i32* %2
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %62
16: ; preds = %12
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = load i32, i32* %2
%21 = call i64 @is_ws(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %4
%27 = call i32 @showbits(i32 %26)
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = call i32 @rightrot(i32 %28, i32 %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = call i32 @showbits(i32 %33)
store i32 0, i32* %3
store i32 0, i32* %5
br label %61
35: ; preds = %19, %16
%36 = load i32, i32* %3
%37 = icmp ne i32 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %35
%39 = load i32, i32* %2
%40 = call i64 @is_num(i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i32, i32* %2
%44 = sub nsw i32 %43, 48
store i32 %44, i32* %5
store i32 1, i32* %3
br label %60
45: ; preds = %38, %35
%46 = load i32, i32* %3
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %58
48: ; preds = %45
%49 = load i32, i32* %2
%50 = call i64 @is_num(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load i32, i32* %5
%54 = mul i32 %53, 10
%55 = load i32, i32* %2
%56 = add i32 %54, %55
%57 = sub i32 %56, 48
store i32 %57, i32* %5
br label %59
58: ; preds = %48, %45
store i32 0, i32* %3
store i32 0, i32* %5
br label %59
59: ; preds = %58, %52
br label %60
60: ; preds = %59, %42
br label %61
61: ; preds = %60, %23
br label %12
62: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@UINT_MAX = global i32 0
@maxbit = external global i32
@EOF = global i32 0
@.str = [22 x i8] c"Old bit field:\0A\09%u = \00"
@.str.1 = [22 x i8] c"New bit field:\0A\09%u = \00"
define i32 @main() {
%1 = load i32, i32* @UINT_MAX
%2 = tail call i32 @l_m_bit(i32 %1)
store i32 %2, i32* @maxbit
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %46, label %6
6: ; preds = %0
%7 = lshr i32 %2, 1
%8 = shl nsw i32 -1, %7
%9 = xor i32 %8, -1
br label %10
10: ; preds = %6, %39
%11 = phi i32 [ %43, %39 ], [ %3, %6 ]
%12 = phi i32 [ %42, %39 ], [ 0, %6 ]
%13 = phi i32 [ %41, %39 ], [ %9, %6 ]
%14 = phi i32 [ %40, %39 ], [ 0, %6 ]
%15 = icmp eq i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %10
%17 = tail call i64 @is_ws(i32 %11)
%18 = icmp eq i64 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %16
%20 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %13)
%21 = tail call i32 @showbits(i32 %13)
%22 = tail call i32 @rightrot(i32 %13, i32 %12)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = tail call i32 @showbits(i32 %22)
br label %39
25: ; preds = %10
%26 = tail call i64 @is_num(i32 %11)
%27 = icmp eq i64 %26, 0
%28 = add nsw i32 %11, -48
%29 = xor i1 %27, true
%30 = zext i1 %29 to i32
%31 = select i1 %27, i32 0, i32 %28
br label %39
32: ; preds = %16
%33 = tail call i64 @is_num(i32 %11)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %32
%36 = mul i32 %12, 10
%37 = add i32 %11, -48
%38 = add i32 %37, %36
br label %39
39: ; preds = %25, %32, %35, %19
%40 = phi i32 [ 0, %19 ], [ 1, %35 ], [ 0, %32 ], [ %30, %25 ]
%41 = phi i32 [ %22, %19 ], [ %13, %35 ], [ %13, %32 ], [ %13, %25 ]
%42 = phi i32 [ 0, %19 ], [ %38, %35 ], [ 0, %32 ], [ %31, %25 ]
%43 = tail call i32 (...) @getchar()
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %10
46: ; preds = %39, %0
ret i32 0
}