#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double atof(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *strchr(char *, char);
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  char *inm = argv[1], *onm = argv[2];
  FILE *fin = fopen(inm, "r");
  char *buf = malloc(256);
  printf("# time   MOSI  MISO\n");
  double told = 0.;
  do {
    size_t len = 256;
    if (getline(&buf, &len, fin) < 1)
      break;
    char *brace;
    if (!(brace = strchr(buf, '(')))
      continue;
    double t;
    int mosi, miso;
    t = atof(buf);
    ++brace;
    mosi = strtol(brace, NULL, 16);
    if (!(brace = strchr(brace, '(')))
      continue;
    miso = strtol(brace + 1, NULL, 16);
    if (t - told > 0.001)
      printf("\n");
    printf("%7.5f  %.2x  %.2x\n", t, mosi >> 1, miso >> 1);
    told = t;
  } while (1);
  fclose(fin);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x100,-0x40(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <getline@plt>
cmp    $0x1,%eax
jge    120d <main+0x8d>
jmp    12f9 <main+0x179>
mov    -0x30(%rbp),%rdi
mov    $0x28,%esi
call   1050 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    122e <main+0xae>
jmp    12ea <main+0x16a>
mov    -0x30(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %eax,-0x54(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x28,%esi
call   1050 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    127e <main+0xfe>
jmp    12ea <main+0x16a>
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %eax,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  0xd57(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12c1 <main+0x141>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movsd  -0x50(%rbp),%xmm0
mov    -0x54(%rbp),%esi
sar    $0x1,%esi
mov    -0x58(%rbp),%edx
sar    $0x1,%edx
lea    0xd46(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    11e6 <main+0x66>
jmp    12f9 <main+0x179>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x8(%rsi),%rdi
lea    0xe4f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r13
mov    $0x100,%edi
call   10a0 <malloc@plt>
mov    %rax,0x18(%rsp)
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
movq   $0x100,0x10(%rsp)
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
call   10c0 <getline@plt>
test   %eax,%eax
jle    12f8 <main+0x158>
xorps  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
lea    0x18(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xdf1(%rip),%r12
jmp    125d <main+0xbd>
nopl   0x0(%rax,%rax,1)
sar    %ebp
sar    %ebx
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    $0x1,%al
call   1080 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movq   $0x100,0x10(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   10c0 <getline@plt>
test   %eax,%eax
jle    12f8 <main+0x158>
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x28,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     123e <main+0x9e>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x8(%rsp)
add    $0x1,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <strtol@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x28,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     123e <main+0x9e>
add    $0x1,%rax
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <strtol@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
subsd  0x20(%rsp),%xmm0
ucomisd 0xd27(%rip),%xmm0
movapd %xmm1,%xmm0
jbe    1220 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x8(%rsp),%xmm0
jmp    1220 <main+0x80>
mov    %r13,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"# time MOSI MISO\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [19 x i8] c"%7.5f %.2x %.2x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca double
%11 = alloca i64
%12 = alloca i8*
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
store i8* %21, i8** %7
%22 = load i8*, i8** %6
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %8
%24 = call i8* @malloc(i32 256)
store i8* %24, i8** %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store double 0.000000e+00, double* %10
br label %26
26: ; preds = %65, %2
store i64 256, i64* %11
%27 = load i32*, i32** %8
%28 = call i32 @getline(i8** %9, i64* %11, i32* %27)
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %26
br label %66
31: ; preds = %26
%32 = load i8*, i8** %9
%33 = call i8* @strchr(i8* %32, i8 signext 40)
store i8* %33, i8** %12
%34 = icmp ne i8* %33, null
br i1 %34, label %36, label %35
35: ; preds = %31
br label %65
36: ; preds = %31
%37 = load i8*, i8** %9
%38 = call double @atof(i8* %37)
store double %38, double* %13
%39 = load i8*, i8** %12
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %12
%41 = load i8*, i8** %12
%42 = call i32 @strtol(i8* %41, i32* null, i32 16)
store i32 %42, i32* %14
%43 = load i8*, i8** %12
%44 = call i8* @strchr(i8* %43, i8 signext 40)
store i8* %44, i8** %12
%45 = icmp ne i8* %44, null
br i1 %45, label %47, label %46
46: ; preds = %36
br label %65
47: ; preds = %36
%48 = load i8*, i8** %12
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = call i32 @strtol(i8* %49, i32* null, i32 16)
store i32 %50, i32* %15
%51 = load double, double* %13
%52 = load double, double* %10
%53 = fsub double %51, %52
%54 = fcmp ogt double %53, 1.000000e-03
br i1 %54, label %55, label %57
55: ; preds = %47
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %55, %47
%58 = load double, double* %13
%59 = load i32, i32* %14
%60 = ashr i32 %59, 1
%61 = load i32, i32* %15
%62 = ashr i32 %61, 1
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double %58, i32 %60, i32 %62)
%64 = load double, double* %13
store double %64, double* %10
br label %65
65: ; preds = %57, %46, %35
br i1 true, label %26, label %66
66: ; preds = %65, %30
%67 = load i32*, i32** %8
%68 = call i32 @fclose(i32* %67)
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"%7.5f %.2x %.2x\0A\00"
@str = [20 x i8] c"# time MOSI MISO\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = bitcast i8** %3 to i8*
%9 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
store i8* %9, i8** %3
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%11 = bitcast i64* %4 to i8*
store i64 256, i64* %4
%12 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%13 = icmp slt i32 %12, 1
br i1 %13, label %40, label %14
14: ; preds = %2, %36
%15 = phi double [ %37, %36 ], [ 0.000000e+00, %2 ]
%16 = load i8*, i8** %3
%17 = call i8* @strchr(i8* dereferenceable(1) %16, i8 signext 40)
%18 = icmp eq i8* %17, null
br i1 %18, label %36, label %19
19: ; preds = %14
%20 = call double @atof(i8* %16)
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = call i32 @strtol(i8* nocapture %21, i32* null, i32 16)
%23 = call i8* @strchr(i8* %21, i8 signext 40)
%24 = icmp eq i8* %23, null
br i1 %24, label %36, label %25
25: ; preds = %19
%26 = getelementptr inbounds i8, i8* %23, i64 1
%27 = call i32 @strtol(i8* nocapture %26, i32* null, i32 16)
%28 = fsub double %20, %15
%29 = fcmp ogt double %28, 1.000000e-03
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @putchar(i32 10)
br label %32
32: ; preds = %30, %25
%33 = ashr i32 %22, 1
%34 = ashr i32 %27, 1
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double %20, i32 %33, i32 %34)
br label %36
36: ; preds = %14, %19, %32
%37 = phi double [ %15, %14 ], [ %20, %32 ], [ %15, %19 ]
store i64 256, i64* %4
%38 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%39 = icmp slt i32 %38, 1
br i1 %39, label %40, label %14
40: ; preds = %36, %2
%41 = call i32 @fclose(i32* %7)
ret i32 0
}