#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*/ O_RDONLY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, float);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char buf[4096];
  int fd = open("inputcap", O_RDONLY);
  memset(buf, 0, 4096);
  int ret = read(fd, buf, 4000);
  if (ret < 0)
    exit(0);
  int i;
  int count;
  for (i = 0; i < 4000; ++i) {
    char byte = buf[i];
    int mask = 0x80;
    while (mask) {
      if (mask & byte)
        ++count;
      mask >>= 1;
    }
  }
  printf("Distance = %6d us, %6.2f inches\n", count, (float)count / 148.0f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1014(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    -0x1014(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0xfa0,%edx
call   1050 <read@plt>
mov    %eax,-0x1018(%rbp)
cmpl   $0x0,-0x1018(%rbp)
jge    11c8 <main+0x78>
xor    %edi,%edi
call   1070 <exit@plt>
movl   $0x0,-0x101c(%rbp)
cmpl   $0xfa0,-0x101c(%rbp)
jge    1261 <main+0x111>
movslq -0x101c(%rbp),%rax
mov    -0x1010(%rbp,%rax,1),%al
mov    %al,-0x1021(%rbp)
movl   $0x80,-0x1028(%rbp)
cmpl   $0x0,-0x1028(%rbp)
je     1248 <main+0xf8>
mov    -0x1028(%rbp),%eax
movsbl -0x1021(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1234 <main+0xe4>
mov    -0x1020(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1020(%rbp)
mov    -0x1028(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x1028(%rbp)
jmp    1200 <main+0xb0>
jmp    124d <main+0xfd>
mov    -0x101c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x101c(%rbp)
jmp    11d2 <main+0x82>
mov    -0x1020(%rbp),%esi
cvtsi2ssl -0x1020(%rbp),%xmm0
ff
movss  0xd89(%rip),%xmm1
divss  %xmm1,%xmm0
lea    0xd8b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xfa0,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1339 <main+0x1e9>
pxor   %xmm8,%xmm8
mov    $0x4,%eax
movdqa 0xe53(%rip),%xmm9
pxor   %xmm5,%xmm5
pxor   %xmm4,%xmm4
cs nopw 0x0(%rax,%rax,1)
nop
movq   -0x4(%rsp,%rax,1),%xmm0
movd   (%rsp,%rax,1),%xmm1
punpcklbw %xmm8,%xmm0
punpcklwd %xmm8,%xmm0
punpcklbw %xmm8,%xmm1
punpcklwd %xmm8,%xmm1
movdqa %xmm0,%xmm7
psrld  $0x7,%xmm7
paddd  %xmm5,%xmm7
movdqa %xmm1,%xmm5
psrld  $0x7,%xmm5
paddd  %xmm4,%xmm5
movdqa %xmm0,%xmm3
psrld  $0x6,%xmm3
movdqa %xmm1,%xmm6
psrld  $0x6,%xmm6
pand   %xmm9,%xmm3
paddd  %xmm7,%xmm3
pand   %xmm9,%xmm6
paddd  %xmm5,%xmm6
movdqa %xmm0,%xmm7
psrld  $0x5,%xmm7
movdqa %xmm1,%xmm2
psrld  $0x5,%xmm2
pand   %xmm9,%xmm7
pand   %xmm9,%xmm2
movdqa %xmm0,%xmm5
psrld  $0x4,%xmm5
movdqa %xmm1,%xmm4
psrld  $0x4,%xmm4
pand   %xmm9,%xmm5
paddd  %xmm7,%xmm5
paddd  %xmm3,%xmm5
pand   %xmm9,%xmm4
paddd  %xmm2,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm2
psrld  $0x3,%xmm2
movdqa %xmm1,%xmm3
psrld  $0x3,%xmm3
pand   %xmm9,%xmm2
pand   %xmm9,%xmm3
movdqa %xmm0,%xmm6
psrld  $0x2,%xmm6
movdqa %xmm1,%xmm7
psrld  $0x2,%xmm7
pand   %xmm9,%xmm6
paddd  %xmm2,%xmm6
pand   %xmm9,%xmm7
paddd  %xmm3,%xmm7
movdqa %xmm0,%xmm2
psrld  $0x1,%xmm2
movdqa %xmm1,%xmm3
psrld  $0x1,%xmm3
pand   %xmm9,%xmm2
paddd  %xmm6,%xmm2
paddd  %xmm5,%xmm2
pand   %xmm9,%xmm3
paddd  %xmm7,%xmm3
paddd  %xmm4,%xmm3
pand   %xmm9,%xmm0
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
pand   %xmm9,%xmm1
movdqa %xmm1,%xmm4
paddd  %xmm3,%xmm4
add    $0x8,%rax
cmp    $0xfa4,%rax
jne    11c0 <main+0x70>
paddd  %xmm5,%xmm4
pshufd $0xee,%xmm4,%xmm0
paddd  %xmm4,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%esi
cvtdq2ps %xmm1,%xmm0
divss  0xcf0(%rip),%xmm0
lea    0xcf6(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"inputcap\00"
@O_RDONLY = global i32 0
@.str.1 = [33 x i8] c"Distance = %6d us, %6.2f inches\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %7
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 4096)
%17 = load i32, i32* %7
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 4000)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %2
store i32 0, i32* %9
br label %25
25: ; preds = %49, %24
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 4000
br i1 %27, label %28, label %52
28: ; preds = %25
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %30
%32 = load i8, i8* %31
store i8 %32, i8* %11
store i32 128, i32* %12
br label %33
33: ; preds = %45, %28
%34 = load i32, i32* %12
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %48
36: ; preds = %33
%37 = load i32, i32* %12
%38 = load i8, i8* %11
%39 = sext i8 %38 to i32
%40 = and i32 %37, %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %45
45: ; preds = %42, %36
%46 = load i32, i32* %12
%47 = ashr i32 %46, 1
store i32 %47, i32* %12
br label %33
48: ; preds = %33
br label %49
49: ; preds = %48
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %25
52: ; preds = %25
%53 = load i32, i32* %10
%54 = load i32, i32* %10
%55 = sitofp i32 %54 to float
%56 = fdiv float %55, 1.480000e+02
%57 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %53, float %56)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"inputcap\00"
@O_RDONLY = global i32 0
@.str.1 = [33 x i8] c"Distance = %6d us, %6.2f inches\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @memset(i8* %4, i32 0, i32 4096)
%8 = call i32 @read(i32 %6, i8* %4, i32 4000)
%9 = icmp slt i32 %8, 0
br i1 %9, label %74, label %10
10: ; preds = %2, %10
%11 = phi i64 [ %66, %10 ], [ 0, %2 ]
%12 = phi <4 x i32> [ %64, %10 ], [ <i32 undef, i32 0, i32 0, i32 0>, %2 ]
%13 = phi <4 x i32> [ %65, %10 ], [ zeroinitializer, %2 ]
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %11
%15 = bitcast i8* %14 to <4 x i8>*
%16 = load <4 x i8>, <4 x i8>* %15
%17 = getelementptr inbounds i8, i8* %14, i64 4
%18 = bitcast i8* %17 to <4 x i8>*
%19 = load <4 x i8>, <4 x i8>* %18
%20 = zext <4 x i8> %16 to <4 x i32>
%21 = zext <4 x i8> %19 to <4 x i32>
%22 = lshr <4 x i32> %20, <i32 7, i32 7, i32 7, i32 7>
%23 = lshr <4 x i32> %21, <i32 7, i32 7, i32 7, i32 7>
%24 = add <4 x i32> %12, %22
%25 = add <4 x i32> %13, %23
%26 = lshr <4 x i32> %20, <i32 6, i32 6, i32 6, i32 6>
%27 = lshr <4 x i32> %21, <i32 6, i32 6, i32 6, i32 6>
%28 = and <4 x i32> %26, <i32 1, i32 1, i32 1, i32 1>
%29 = and <4 x i32> %27, <i32 1, i32 1, i32 1, i32 1>
%30 = add <4 x i32> %24, %28
%31 = add <4 x i32> %25, %29
%32 = lshr <4 x i32> %20, <i32 5, i32 5, i32 5, i32 5>
%33 = lshr <4 x i32> %21, <i32 5, i32 5, i32 5, i32 5>
%34 = and <4 x i32> %32, <i32 1, i32 1, i32 1, i32 1>
%35 = and <4 x i32> %33, <i32 1, i32 1, i32 1, i32 1>
%36 = add <4 x i32> %30, %34
%37 = add <4 x i32> %31, %35
%38 = lshr <4 x i32> %20, <i32 4, i32 4, i32 4, i32 4>
%39 = lshr <4 x i32> %21, <i32 4, i32 4, i32 4, i32 4>
%40 = and <4 x i32> %38, <i32 1, i32 1, i32 1, i32 1>
%41 = and <4 x i32> %39, <i32 1, i32 1, i32 1, i32 1>
%42 = add <4 x i32> %36, %40
%43 = add <4 x i32> %37, %41
%44 = lshr <4 x i32> %20, <i32 3, i32 3, i32 3, i32 3>
%45 = lshr <4 x i32> %21, <i32 3, i32 3, i32 3, i32 3>
%46 = and <4 x i32> %44, <i32 1, i32 1, i32 1, i32 1>
%47 = and <4 x i32> %45, <i32 1, i32 1, i32 1, i32 1>
%48 = add <4 x i32> %42, %46
%49 = add <4 x i32> %43, %47
%50 = lshr <4 x i32> %20, <i32 2, i32 2, i32 2, i32 2>
%51 = lshr <4 x i32> %21, <i32 2, i32 2, i32 2, i32 2>
%52 = and <4 x i32> %50, <i32 1, i32 1, i32 1, i32 1>
%53 = and <4 x i32> %51, <i32 1, i32 1, i32 1, i32 1>
%54 = add <4 x i32> %48, %52
%55 = add <4 x i32> %49, %53
%56 = lshr <4 x i32> %20, <i32 1, i32 1, i32 1, i32 1>
%57 = lshr <4 x i32> %21, <i32 1, i32 1, i32 1, i32 1>
%58 = and <4 x i32> %56, <i32 1, i32 1, i32 1, i32 1>
%59 = and <4 x i32> %57, <i32 1, i32 1, i32 1, i32 1>
%60 = add <4 x i32> %54, %58
%61 = add <4 x i32> %55, %59
%62 = and <4 x i32> %20, <i32 1, i32 1, i32 1, i32 1>
%63 = and <4 x i32> %21, <i32 1, i32 1, i32 1, i32 1>
%64 = add <4 x i32> %60, %62
%65 = add <4 x i32> %61, %63
%66 = add nuw i64 %11, 8
%67 = icmp eq i64 %66, 4000
br i1 %67, label %68, label %10
68: ; preds = %10
%69 = add <4 x i32> %65, %64
%70 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %69)
%71 = sitofp i32 %70 to float
%72 = fdiv float %71, 1.480000e+02
%73 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %70, float %72)
ret i32 0
74: ; preds = %2
%75 = call i32 @exit(i32 0)
unreachable
}