#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 scanf(char *, int *);
int main() {
  int accumulate = 0;
  int hex = 0;
  int count = 0;
  while (scanf("%x", &hex) == 1) {
    count += 1;
    accumulate += hex << (8 * (count - 1));
    if (count == 4) {
      printf("%#.8x\n", accumulate);
      accumulate = 0;
      count = 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb5(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11a6 <main+0x86>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
shl    $0x3,%ecx
shl    %cl,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x4,-0x10(%rbp)
jne    11a1 <main+0x81>
mov    -0x8(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    1144 <main+0x24>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xec5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11a7 <main+0x87>
xor    %ecx,%ecx
lea    0xeb0(%rip),%r14
lea    0xea6(%rip),%r15
lea    0xc(%rsp),%r12
xor    %edx,%edx
jmp    1184 <main+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    %ebx,%ecx
mov    %ebp,%edx
cmp    $0x1,%eax
jne    11a7 <main+0x87>
lea    0x1(%rcx),%ebx
mov    0xc(%rsp),%ebp
shl    $0x3,%ecx
shl    %cl,%ebp
add    %edx,%ebp
cmp    $0x4,%ebx
jne    1170 <main+0x50>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1170 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
@.str.1 = [7 x i8] c"%#.8x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %23, %0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
store i32 %10, i32* %4
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = mul nsw i32 8, %13
%15 = shl i32 %11, %14
%16 = load i32, i32* %2
%17 = add nsw i32 %16, %15
store i32 %17, i32* %2
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 4
br i1 %19, label %20, label %23
20: ; preds = %8
%21 = load i32, i32* %2
%22 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 0, i32* %2
store i32 0, i32* %4
br label %23
23: ; preds = %20, %8
br label %5
24: ; preds = %5
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
@.str.1 = [7 x i8] c"%#.8x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %21
5: ; preds = %0, %16
%6 = phi i32 [ %18, %16 ], [ 0, %0 ]
%7 = phi i32 [ %17, %16 ], [ 0, %0 ]
%8 = add nsw i32 %6, 1
%9 = load i32, i32* %1
%10 = shl nsw i32 %6, 3
%11 = shl i32 %9, %10
%12 = add nsw i32 %11, %7
%13 = icmp eq i32 %8, 4
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %16
16: ; preds = %14, %5
%17 = phi i32 [ 0, %14 ], [ %12, %5 ]
%18 = phi i32 [ 0, %14 ], [ %8, %5 ]
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%20 = icmp eq i32 %19, 1
br i1 %20, label %5, label %21
21: ; preds = %16, %0
ret i32 0
}