#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 get1();
long getNum(void) {
  int cnt = get1() / 4;
  long n = get1();
  int i = 0;
  while (--cnt)
    n |= get1() << (i += 8);
  if (n & 1)
    n = -n;
  return n / 2;
}


x86 assembly (clang, -O0):
<getNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <get1@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <get1@plt>
cltq
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     1171 <getNum+0x61>
mov    $0x0,%al
call   1030 <get1@plt>
mov    -0x14(%rbp),%ecx
add    $0x8,%ecx
mov    %ecx,-0x14(%rbp)
shl    %cl,%eax
cltq
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    113e <getNum+0x2e>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     118d <getNum+0x7d>
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNum>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <get1@plt>
lea    0x3(%rax),%ebp
test   %eax,%eax
cmovns %eax,%ebp
sar    $0x2,%ebp
xor    %eax,%eax
call   1030 <get1@plt>
movslq %eax,%r14
add    $0xffffffff,%ebp
je     1158 <getNum+0x48>
mov    $0x8,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <get1@plt>
mov    %ebx,%ecx
shl    %cl,%eax
cltq
or     %rax,%r14
add    $0x8,%ebx
add    $0xffffffff,%ebp
jne    1140 <getNum+0x30>
mov    %r14,%rcx
neg    %rcx
test   $0x1,%r14b
cmove  %r14,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
add    %rcx,%rax
sar    %rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i64 @getNum() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = call i32 (...) @get1()
%5 = sdiv i32 %4, 4
store i32 %5, i32* %1
%6 = call i32 (...) @get1()
%7 = sext i32 %6 to i64
store i64 %7, i64* %2
store i32 0, i32* %3
br label %8
8: ; preds = %12, %0
%9 = load i32, i32* %1
%10 = add nsw i32 %9, -1
store i32 %10, i32* %1
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = call i32 (...) @get1()
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 8
store i32 %15, i32* %3
%16 = shl i32 %13, %15
%17 = sext i32 %16 to i64
%18 = load i64, i64* %2
%19 = or i64 %18, %17
store i64 %19, i64* %2
br label %8
20: ; preds = %8
%21 = load i64, i64* %2
%22 = and i64 %21, 1
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i64, i64* %2
%26 = sub nsw i64 0, %25
store i64 %26, i64* %2
br label %27
27: ; preds = %24, %20
%28 = load i64, i64* %2
%29 = sdiv i64 %28, 2
ret i64 %29
}

LLVM IR (-O2):
define i64 @getNum() {
%1 = tail call i32 (...) @get1()
%2 = sdiv i32 %1, 4
%3 = tail call i32 (...) @get1()
%4 = sext i32 %3 to i64
%5 = add nsw i32 %2, -1
%6 = icmp eq i32 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %16, %7 ], [ %5, %0 ]
%9 = phi i32 [ %12, %7 ], [ 0, %0 ]
%10 = phi i64 [ %15, %7 ], [ %4, %0 ]
%11 = tail call i32 (...) @get1()
%12 = add nuw nsw i32 %9, 8
%13 = shl i32 %11, %12
%14 = sext i32 %13 to i64
%15 = or i64 %10, %14
%16 = add nsw i32 %8, -1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %7
18: ; preds = %7, %0
%19 = phi i64 [ %4, %0 ], [ %15, %7 ]
%20 = and i64 %19, 1
%21 = icmp eq i64 %20, 0
%22 = sub nsw i64 0, %19
%23 = select i1 %21, i64 %19, i64 %22
%24 = sdiv i64 %23, 2
ret i64 %24
}