#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 */
struct canfd_frame {
  int dummy;
};

/* Variables and functions */
int CANFD_MAX_DLEN;
int CANFD_MTU;
int CAN_MAX_DLEN;
int CAN_MTU;
int IFNAMSIZ;
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int parse_canframe(char *, struct canfd_frame *);
int /*<<< orphan*/ printf(char *, char *, char *, char *);
int /*<<< orphan*/ sprint_long_canframe(char *, struct canfd_frame *, int, int);
int sscanf(char *, char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char buf[(sizeof("(1345212884.318850)") + IFNAMSIZ + 4 +
            (2 * (sizeof("12345678##1")) + 64 * sizeof(".AA")) + 200)],
      timestamp[(sizeof("(1345212884.318850)") + IFNAMSIZ + 4 +
                 (2 * (sizeof("12345678##1")) + 64 * sizeof(".AA")) + 200)],
      device[(sizeof("(1345212884.318850)") + IFNAMSIZ + 4 +
              (2 * (sizeof("12345678##1")) + 64 * sizeof(".AA")) + 200)],
      ascframe[(sizeof("(1345212884.318850)") + IFNAMSIZ + 4 +
                (2 * (sizeof("12345678##1")) + 64 * sizeof(".AA")) + 200)];
  struct canfd_frame cf;
  int mtu, maxdlen;
  while (fgets(buf,
               (sizeof("(1345212884.318850)") + IFNAMSIZ + 4 +
                (2 * (sizeof("12345678##1")) + 64 * sizeof(".AA")) + 200) -
                   1,
               stdin)) {
    if (sscanf(buf, "%s %s %s", timestamp, device, ascframe) != 3)
      return 1;
    mtu = parse_canframe(ascframe, &cf);
    if (mtu == CAN_MTU)
      maxdlen = CAN_MAX_DLEN;
    else if (mtu == CANFD_MTU)
      maxdlen = CANFD_MAX_DLEN;
    else {
      fprintf(stderr, "read: incomplete CAN frame\n");
      return 1;
    }
    sprint_long_canframe(ascframe, &cf, (0x10 | 0x1), maxdlen);
    printf("%s  %s  %s\n", timestamp, device, ascframe);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
movslq (%rax),%rsi
mov    %rsi,%rcx
add    $0x1f8,%rcx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
add    $0x207,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x70(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
movslq (%rax),%rsi
mov    %rsi,%rcx
add    $0x1f8,%rcx
add    $0x207,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
movslq (%rax),%rsi
mov    %rsi,%rcx
add    $0x1f8,%rcx
add    $0x207,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
movslq (%rax),%rdx
mov    %rdx,%rax
add    $0x1f8,%rax
add    $0x207,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x70(%rbp),%rdi
mov    0x2d86(%rip),%rax
movslq (%rax),%rax
add    $0x14,%rax
add    $0x4,%rax
add    $0x118,%rax
add    $0xc8,%rax
sub    $0x1,%rax
mov    %eax,%esi
mov    0x2d8a(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1354 <main+0x1f4>
mov    -0x58(%rbp),%r8
mov    -0x60(%rbp),%rcx
mov    -0x68(%rbp),%rdx
mov    -0x70(%rbp),%rdi
lea    0xd82(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x3,%eax
je     129f <main+0x13f>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1362 <main+0x202>
mov    -0x58(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <parse_canframe@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    0x2cf7(%rip),%rcx
cmp    (%rcx),%eax
jne    12d2 <main+0x172>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
jmp    1322 <main+0x1c2>
mov    -0x44(%rbp),%eax
mov    0x2d0c(%rip),%rcx
cmp    (%rcx),%eax
jne    12f5 <main+0x195>
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
jmp    131d <main+0x1bd>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xd04(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1362 <main+0x202>
jmp    1322 <main+0x1c2>
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%ecx
lea    -0x40(%rbp),%rsi
mov    $0x11,%edx
call   1040 <sprint_long_canframe@plt>
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rcx
lea    0xcdb(%rip),%rdi
call   1030 <printf@plt>
jmp    1227 <main+0xc7>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e43(%rip),%rax
movslq (%rax),%rax
mov    %rsp,%r15
mov    %rax,%rcx
add    $0x207,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r15
mov    %r15,%rsp
mov    %rsp,%r14
sub    %rcx,%r14
mov    %r14,%rsp
mov    %rsp,%r12
sub    %rcx,%r12
mov    %r12,%rsp
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    0x1f7(%rax),%esi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
call   1050 <fgets@plt>
test   %rax,%rax
je     129a <main+0x13a>
mov    $0x1,%r13d
jmp    122e <main+0xce>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rcx),%ecx
mov    %rbx,%rdi
lea    -0x30(%rbp),%rsi
mov    $0x11,%edx
call   1040 <sprint_long_canframe@plt>
lea    0xe2b(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1030 <printf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
mov    $0x1f7,%eax
add    %eax,%esi
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
call   1050 <fgets@plt>
test   %rax,%rax
je     129a <main+0x13a>
mov    %r15,%rdi
lea    0xdc8(%rip),%rsi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
call   1080 <sscanf@plt>
cmp    $0x3,%eax
jne    129d <main+0x13d>
mov    %rbx,%rdi
lea    -0x30(%rbp),%rsi
call   1070 <parse_canframe@plt>
mov    0x2d72(%rip),%rcx
mov    0x2d4b(%rip),%rdx
cmp    (%rdx),%eax
je     11e0 <main+0x80>
mov    0x2d54(%rip),%rcx
mov    0x2d6d(%rip),%rdx
cmp    (%rdx),%eax
je     11e0 <main+0x80>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
call   1060 <fprintf@plt>
jmp    129d <main+0x13d>
xor    %r13d,%r13d
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.canfd_frame = type { i32 }
@IFNAMSIZ = global i32 0
@stdin = global i32 0
@.str = [9 x i8] c"%s %s %s\00"
@CAN_MTU = global i32 0
@CAN_MAX_DLEN = global i32 0
@CANFD_MTU = global i32 0
@CANFD_MAX_DLEN = global i32 0
@stderr = global i32 0
@.str.1 = [28 x i8] c"read: incomplete CAN frame\0A\00"
@.str.2 = [12 x i8] c"%s %s %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca %struct.canfd_frame
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @IFNAMSIZ
%16 = sext i32 %15 to i64
%17 = add i64 20, %16
%18 = add i64 %17, 4
%19 = add i64 %18, 280
%20 = add i64 %19, 200
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %6
%22 = alloca i8, i64 %20
store i64 %20, i64* %7
%23 = load i32, i32* @IFNAMSIZ
%24 = sext i32 %23 to i64
%25 = add i64 20, %24
%26 = add i64 %25, 4
%27 = add i64 %26, 280
%28 = add i64 %27, 200
%29 = alloca i8, i64 %28
store i64 %28, i64* %8
%30 = load i32, i32* @IFNAMSIZ
%31 = sext i32 %30 to i64
%32 = add i64 20, %31
%33 = add i64 %32, 4
%34 = add i64 %33, 280
%35 = add i64 %34, 200
%36 = alloca i8, i64 %35
store i64 %35, i64* %9
%37 = load i32, i32* @IFNAMSIZ
%38 = sext i32 %37 to i64
%39 = add i64 20, %38
%40 = add i64 %39, 4
%41 = add i64 %40, 280
%42 = add i64 %41, 200
%43 = alloca i8, i64 %42
store i64 %42, i64* %10
br label %44
44: ; preds = %77, %2
%45 = load i32, i32* @IFNAMSIZ
%46 = sext i32 %45 to i64
%47 = add i64 20, %46
%48 = add i64 %47, 4
%49 = add i64 %48, 280
%50 = add i64 %49, 200
%51 = sub i64 %50, 1
%52 = trunc i64 %51 to i32
%53 = load i32, i32* @stdin
%54 = call i64 @fgets(i8* %22, i32 %52, i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %81
56: ; preds = %44
%57 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %36, i8* %43)
%58 = icmp ne i32 %57, 3
br i1 %58, label %59, label %60
59: ; preds = %56
store i32 1, i32* %3
store i32 1, i32* %14
br label %82
60: ; preds = %56
%61 = call i32 @parse_canframe(i8* %43, %struct.canfd_frame* %11)
store i32 %61, i32* %12
%62 = load i32, i32* %12
%63 = load i32, i32* @CAN_MTU
%64 = icmp eq i32 %62, %63
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = load i32, i32* @CAN_MAX_DLEN
store i32 %66, i32* %13
br label %77
67: ; preds = %60
%68 = load i32, i32* %12
%69 = load i32, i32* @CANFD_MTU
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = load i32, i32* @CANFD_MAX_DLEN
store i32 %72, i32* %13
br label %76
73: ; preds = %67
%74 = load i32, i32* @stderr
%75 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %14
br label %82
76: ; preds = %71
br label %77
77: ; preds = %76, %65
%78 = load i32, i32* %13
%79 = call i32 @sprint_long_canframe(i8* %43, %struct.canfd_frame* %11, i32 17, i32 %78)
%80 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %36, i8* %43)
br label %44
81: ; preds = %44
store i32 0, i32* %3
store i32 1, i32* %14
br label %82
82: ; preds = %81, %73, %59
%83 = load i8*, i8** %6
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
%struct.canfd_frame = type { i32 }
@IFNAMSIZ = global i32 0
@stdin = global i32 0
@.str = [9 x i8] c"%s %s %s\00"
@CAN_MTU = global i32 0
@CAN_MAX_DLEN = global i32 0
@CANFD_MTU = global i32 0
@CANFD_MAX_DLEN = global i32 0
@stderr = global i32 0
@.str.1 = [28 x i8] c"read: incomplete CAN frame\0A\00"
@.str.2 = [12 x i8] c"%s %s %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.canfd_frame
%4 = load i32, i32* @IFNAMSIZ
%5 = sext i32 %4 to i64
%6 = add nsw i64 %5, 504
%7 = alloca i8, i64 %6
%8 = alloca i8, i64 %6
%9 = alloca i8, i64 %6
%10 = alloca i8, i64 %6
%11 = bitcast %struct.canfd_frame* %3 to i8*
%12 = add i32 %4, 503
%13 = load i32, i32* @stdin
%14 = call i64 @fgets(i8* %7, i32 %12, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %39, label %16
16: ; preds = %2, %29
%17 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %9, i8* %10)
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %39
19: ; preds = %16
%20 = call i32 @parse_canframe(i8* %10, %struct.canfd_frame* %3)
%21 = load i32, i32* @CAN_MTU
%22 = icmp eq i32 %20, %21
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = load i32, i32* @CANFD_MTU
%25 = icmp eq i32 %20, %24
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %39
29: ; preds = %23, %19
%30 = phi i32* [ @CAN_MAX_DLEN, %19 ], [ @CANFD_MAX_DLEN, %23 ]
%31 = load i32, i32* %30
%32 = call i32 @sprint_long_canframe(i8* %10, %struct.canfd_frame* %3, i32 17, i32 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %9, i8* %10)
%34 = load i32, i32* @IFNAMSIZ
%35 = add i32 %34, 503
%36 = load i32, i32* @stdin
%37 = call i64 @fgets(i8* %7, i32 %35, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %16
39: ; preds = %16, %29, %2, %26
%40 = phi i32 [ 1, %26 ], [ 0, %2 ], [ 1, %16 ], [ 0, %29 ]
ret i32 %40
}