#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 getchar();
scalar_t__ is_num(int);
scalar_t__ is_ws(int);
int log(int);
int /*<<< orphan*/ printf(char *, unsigned int);
unsigned int setbits(unsigned int, unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ showbits(unsigned int);
int main(void) {
  int c, in_num = 0;
  unsigned bf_old = 0, bf_new = 0, pos_new, len_new;
  while ((c = getchar()) != EOF) {
    if (in_num && is_ws(c)) {
      printf("Original bit field:\n\t%u = ", bf_old);
      showbits(bf_old);
      printf("Replacement bit field:\n\t%u = ", bf_new);
      showbits(bf_new);
      pos_new = (unsigned)(log(bf_new) / log(2));
      len_new = pos_new + 1;
      bf_old = setbits(bf_old, pos_new, len_new, bf_new);
      printf("Replaced bit field:\n\t%u = ", bf_old);
      showbits(bf_old);
      in_num = 0;
      bf_new = 0;
    } else if (!in_num && is_num(c)) {
      bf_new = c - '0';
      in_num = 1;
    } else if (in_num && is_num(c)) {
      bf_new = bf_new * 10 + c - '0';
    } else {
      in_num = 0;
      bf_new = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
je     12da <main+0x16a>
cmpl   $0x0,-0xc(%rbp)
je     125e <main+0xee>
mov    -0x8(%rbp),%edi
call   1040 <is_ws@plt>
cmp    $0x0,%rax
je     125e <main+0xee>
mov    -0x10(%rbp),%esi
lea    0xe2d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%edi
call   1030 <showbits@plt>
mov    -0x14(%rbp),%esi
lea    0xe31(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1030 <showbits@plt>
mov    -0x14(%rbp),%edi
call   1090 <log@plt>
mov    %eax,-0x20(%rbp)
mov    $0x2,%edi
call   1090 <log@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1070 <setbits@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xdfb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%edi
call   1030 <showbits@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    12d5 <main+0x165>
cmpl   $0x0,-0xc(%rbp)
jne    128f <main+0x11f>
mov    -0x8(%rbp),%edi
call   1080 <is_num@plt>
cmp    $0x0,%rax
je     128f <main+0x11f>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    12d0 <main+0x160>
cmpl   $0x0,-0xc(%rbp)
je     12bd <main+0x14d>
mov    -0x8(%rbp),%edi
call   1080 <is_num@plt>
cmp    $0x0,%rax
je     12bd <main+0x14d>
imul   $0xa,-0x14(%rbp),%eax
add    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    12cb <main+0x15b>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    12d0 <main+0x160>
jmp    12d5 <main+0x165>
jmp    1194 <main+0x24>
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
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e5f(%rip),%r14
cmp    (%r14),%eax
jne    119f <main+0x2f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
lea    0xe91(%rip),%r12
xor    %r15d,%r15d
xor    %r13d,%r13d
xor    %ebp,%ebp
jmp    11ea <main+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1080 <is_num@plt>
add    $0xffffffd0,%ebx
xor    %r15d,%r15d
test   %rax,%rax
setne  %r15b
mov    $0x0,%eax
cmove  %eax,%ebx
mov    %ebx,%ebp
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
je     118e <main+0x1e>
mov    %ebx,%edi
test   %r15d,%r15d
je     11c0 <main+0x50>
call   1040 <is_ws@plt>
test   %rax,%rax
je     1270 <main+0x100>
lea    0xdfe(%rip),%rdi
mov    %r13d,%esi
call   1050 <printf@plt>
mov    %r13d,%edi
call   1030 <showbits@plt>
lea    0xe02(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1030 <showbits@plt>
mov    %ebp,%edi
call   1090 <log@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   1090 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
lea    0x1(%rax),%edx
mov    %r13d,%edi
mov    %eax,%esi
mov    %ebp,%ecx
call   1070 <setbits@plt>
mov    %eax,%r13d
mov    %r12,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %r13d,%edi
call   1030 <showbits@plt>
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    11dc <main+0x6c>
nop
mov    %ebx,%edi
call   1080 <is_num@plt>
test   %rax,%rax
je     1265 <main+0xf5>
lea    0x0(%rbp,%rbp,4),%eax
lea    (%rbx,%rax,2),%ebp
add    $0xffffffd0,%ebp
mov    $0x1,%r15d
jmp    11dc <main+0x6c>

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

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