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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, int, int, int, int, int, int, int, int);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *, int *, int *, char *,
                          int *, int *, int *, char *, int *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  char *c_file = NULL;
  FILE *fp;
  char line[256];
  if (argc < 2) {
    usage();
    return 0;
  }
  c_file = argv[1];
  fprintf(stderr, "Calibration file \"%s\"\n", c_file);
  fp = fopen(c_file, "r");
  if (fp == NULL) {
    fprintf(stderr, "Cannot open calibration file \n");
    return 0;
  }
  while (fgets(line, 256, fp) != NULL) {
    if (line[0] == 'G') {
      char rem[32];
      int gx, gy, gz, mx, my, mz;
      int grp, ignore;
      sscanf(line, "%s %d %d %d %s %d %d %d %s %d %d", rem, &gx, &gy, &gz, rem,
             &mx, &my, &mz, rem, &grp, &ignore);
      {
        int16_t gx0 = (int16_t)gx;
        int16_t gy0 = (int16_t)gy;
        int16_t gz0 = (int16_t)gz;
        int16_t mx0 = (int16_t)mx;
        int16_t my0 = (int16_t)my;
        int16_t mz0 = (int16_t)mz;
        printf("0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x %2d %d\n",
               (uint16_t)gx0, (uint16_t)gy0, (uint16_t)gz0, (uint16_t)mx0,
               (uint16_t)my0, (uint16_t)mz0, grp, ignore);
      }
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1d0,%rsp
movl   $0x0,-0x24(%rbp)
mov    %edi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpl   $0x2,-0x28(%rbp)
jge    11b5 <main+0x45>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0x0,-0x24(%rbp)
jmp    139c <main+0x22c>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    121e <main+0xae>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
jmp    139c <main+0x22c>
jmp    1223 <main+0xb3>
lea    -0x140(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     138c <main+0x21c>
movsbl -0x140(%rbp),%eax
cmp    $0x47,%eax
jne    1387 <main+0x217>
lea    -0x140(%rbp),%rdi
lea    -0x160(%rbp),%rdx
lea    -0x160(%rbp),%r12
lea    -0x160(%rbp),%r11
lea    0xdc3(%rip),%rsi
lea    -0x164(%rbp),%rcx
lea    -0x168(%rbp),%r8
lea    -0x16c(%rbp),%r9
lea    -0x170(%rbp),%r15
lea    -0x174(%rbp),%r14
lea    -0x178(%rbp),%rbx
lea    -0x17c(%rbp),%r10
lea    -0x180(%rbp),%rax
mov    %r12,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1070 <sscanf@plt>
movslq -0x164(%rbp),%rax
mov    %rax,-0x188(%rbp)
movslq -0x168(%rbp),%rax
mov    %rax,-0x190(%rbp)
movslq -0x16c(%rbp),%rax
mov    %rax,-0x198(%rbp)
movslq -0x170(%rbp),%rax
mov    %rax,-0x1a0(%rbp)
movslq -0x174(%rbp),%rax
mov    %rax,-0x1a8(%rbp)
movslq -0x178(%rbp),%rax
mov    %rax,-0x1b0(%rbp)
mov    -0x188(%rbp),%rax
mov    %eax,%esi
mov    -0x190(%rbp),%rax
mov    %eax,%edx
mov    -0x198(%rbp),%rax
mov    %eax,%ecx
mov    -0x1a0(%rbp),%rax
mov    %eax,%r8d
mov    -0x1a8(%rbp),%rax
mov    %eax,%r9d
mov    -0x1b0(%rbp),%rax
mov    %eax,%r11d
mov    -0x17c(%rbp),%r10d
mov    -0x180(%rbp),%eax
lea    0xce4(%rip),%rdi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <printf@plt>
jmp    1223 <main+0xb3>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1d0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
cmp    $0x1,%edi
jg     1192 <main+0x22>
xor    %eax,%eax
call   1080 <usage@plt>
jmp    12bf <main+0x14f>
mov    0x8(%rsi),%rbx
mov    0x2e43(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe59(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ae <main+0x13e>
mov    %rax,%r15
lea    0x40(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12a4 <main+0x134>
lea    0x20(%rsp),%r14
lea    0x40(%rsp),%r12
lea    0xe61(%rip),%r13
jmp    1219 <main+0xa9>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12a4 <main+0x134>
cmpb   $0x47,0x40(%rsp)
jne    1200 <main+0x90>
sub    $0x8,%rsp
mov    %r12,%rdi
lea    0xe0a(%rip),%rsi
mov    %r14,%rdx
lea    0x24(%rsp),%rcx
lea    0x20(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0x8(%rsp),%rax
push   %rax
lea    0x14(%rsp),%rax
push   %rax
push   %r14
lea    0x28(%rsp),%rax
push   %rax
lea    0x34(%rsp),%rax
push   %rax
lea    0x40(%rsp),%rax
push   %rax
push   %r14
call   1070 <sscanf@plt>
add    $0x40,%rsp
mov    0x1c(%rsp),%esi
mov    0x18(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    0xc(%rsp),%r9d
mov    0x8(%rsp),%eax
mov    0x4(%rsp),%ebp
mov    (%rsp),%ebx
sub    $0x8,%rsp
mov    %r13,%rdi
push   %rbx
push   %rbp
push   %rax
call   1040 <printf@plt>
add    $0x20,%rsp
jmp    1200 <main+0x90>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    12bf <main+0x14f>
mov    0x0(%rbp),%edi
lea    0xd61(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Calibration file \22%s\22\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Cannot open calibration file \0A\00"
@.str.3 = [33 x i8] c"%s %d %d %d %s %d %d %d %s %d %d\00"
@.str.4 = [50 x i8] c"0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x %2d %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca [32 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
%22 = alloca i64
%23 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i32 (...) @usage()
store i32 0, i32* %3
br label %90
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %6
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %6
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %6
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %28
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %90
42: ; preds = %28
br label %43
43: ; preds = %86, %42
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%45 = load i32*, i32** %7
%46 = call i32* @fgets(i8* %44, i32 256, i32* %45)
%47 = icmp ne i32* %46, null
br i1 %47, label %48, label %87
48: ; preds = %43
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 71
br i1 %52, label %53, label %86
53: ; preds = %48
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%56 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%57 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%58 = call i32 @sscanf(i8* %54, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %55, i32* %10, i32* %11, i32* %12, i8* %56, i32* %13, i32* %14, i32* %15, i8* %57, i32* %16, i32* %17)
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
store i64 %60, i64* %18
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
store i64 %62, i64* %19
%63 = load i32, i32* %12
%64 = sext i32 %63 to i64
store i64 %64, i64* %20
%65 = load i32, i32* %13
%66 = sext i32 %65 to i64
store i64 %66, i64* %21
%67 = load i32, i32* %14
%68 = sext i32 %67 to i64
store i64 %68, i64* %22
%69 = load i32, i32* %15
%70 = sext i32 %69 to i64
store i64 %70, i64* %23
%71 = load i64, i64* %18
%72 = trunc i64 %71 to i32
%73 = load i64, i64* %19
%74 = trunc i64 %73 to i32
%75 = load i64, i64* %20
%76 = trunc i64 %75 to i32
%77 = load i64, i64* %21
%78 = trunc i64 %77 to i32
%79 = load i64, i64* %22
%80 = trunc i64 %79 to i32
%81 = load i64, i64* %23
%82 = trunc i64 %81 to i32
%83 = load i32, i32* %16
%84 = load i32, i32* %17
%85 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %72, i32 %74, i32 %76, i32 %78, i32 %80, i32 %82, i32 %83, i32 %84)
br label %86
86: ; preds = %53, %48
br label %43
87: ; preds = %43
%88 = load i32*, i32** %7
%89 = call i32 @fclose(i32* %88)
store i32 0, i32* %3
br label %90
90: ; preds = %87, %39, %26
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Calibration file \22%s\22\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Cannot open calibration file \0A\00"
@.str.3 = [33 x i8] c"%s %d %d %d %s %d %d %d %s %d %d\00"
@.str.4 = [50 x i8] c"0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x %2d %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [32 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = icmp slt i32 %0, 2
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 (...) @usage()
br label %59
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %19)
%22 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %37, label %24
24: ; preds = %17
%25 = call i32* @fgets(i8* %13, i32 256, i32* %22)
%26 = icmp eq i32* %25, null
br i1 %26, label %57, label %27
27: ; preds = %24
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%29 = bitcast i32* %5 to i8*
%30 = bitcast i32* %6 to i8*
%31 = bitcast i32* %7 to i8*
%32 = bitcast i32* %8 to i8*
%33 = bitcast i32* %9 to i8*
%34 = bitcast i32* %10 to i8*
%35 = bitcast i32* %11 to i8*
%36 = bitcast i32* %12 to i8*
br label %40
37: ; preds = %17
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %59
40: ; preds = %27, %54
%41 = load i8, i8* %13
%42 = icmp eq i8 %41, 71
br i1 %42, label %43, label %54
43: ; preds = %40
%44 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %28, i32* %5, i32* %6, i32* %7, i8* %28, i32* %8, i32* %9, i32* %10, i8* %28, i32* %11, i32* %12)
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = load i32, i32* %10
%51 = load i32, i32* %11
%52 = load i32, i32* %12
%53 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %45, i32 %46, i32 %47, i32 %48, i32 %49, i32 %50, i32 %51, i32 %52)
br label %54
54: ; preds = %43, %40
%55 = call i32* @fgets(i8* %13, i32 256, i32* %22)
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %40
57: ; preds = %54, %24
%58 = call i32 @fclose(i32* %22)
br label %59
59: ; preds = %57, %37, %15
ret i32 0
}