#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*/ decode_long_entry(unsigned char const *, long *, int *,
                                     int *, int *, int *);
int /*<<< orphan*/ decode_short_entry(unsigned char const *, long *, int *,
                                      int *, int *, int *);
int /*<<< orphan*/ ecef_to_geo(int, int, int, double *, double *, double *);
int /*<<< orphan*/ output_gpx_trk_point(long, double, double, double, int);
int /*<<< orphan*/ printf(char *);
long process_buffer(const unsigned char *buffer, const int length,
                    const long first_timestamp) {
  int offset = 0;
  long time;
  int ecef_x, ecef_y, ecef_z, speed;
  double latitude, longitude, height;
  int tagged_entry = 0;
  long last_timestamp = first_timestamp;
  ;
  printf("<!-- next sector -->\n");
  while (offset < length) {
    if (buffer[offset] & 0x40) {
      decode_long_entry(buffer + offset, &time, &ecef_x, &ecef_y, &ecef_z,
                        &speed);
      ecef_to_geo(ecef_x, ecef_y, ecef_z, &longitude, &latitude, &height);
      if (buffer[offset] & 0x20) {
        tagged_entry = 1;
      }
      if ((last_timestamp > 0) && (time > (last_timestamp + 3600l))) {
        printf("</trkseg>\n<trkseg>\n");
      }
      output_gpx_trk_point(time, latitude, longitude, height, speed);
      offset += 18;
    } else if (buffer[offset] == 0x80) {
      decode_short_entry(buffer + offset, &time, &ecef_x, &ecef_y, &ecef_z,
                         &speed);
      ecef_to_geo(ecef_x, ecef_y, ecef_z, &longitude, &latitude, &height);
      if ((last_timestamp > 0) && (time > (last_timestamp + 3600l))) {
        printf("</trkseg>\n<trkseg>\n");
      }
      output_gpx_trk_point(time, latitude, longitude, height, speed);
      offset += 8;
    } else {
      offset++;
    }
    last_timestamp = time;
  }
  return last_timestamp;
}


x86 assembly (clang, -O0):
<process_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1326 <process_buffer+0x1d6>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     125e <process_buffer+0x10e>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
lea    -0x38(%rbp),%r9
call   1060 <decode_long_entry@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    -0x48(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x50(%rbp),%r9
call   1070 <ecef_to_geo@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1206 <process_buffer+0xb6>
movl   $0x1,-0x54(%rbp)
cmpq   $0x0,-0x60(%rbp)
jle    1235 <process_buffer+0xe5>
mov    -0x28(%rbp),%rax
mov    -0x60(%rbp),%rcx
add    $0xe10,%rcx
cmp    %rcx,%rax
jle    1235 <process_buffer+0xe5>
lea    0xde6(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
mov    -0x38(%rbp),%esi
call   1040 <output_gpx_trk_point@plt>
mov    -0x1c(%rbp),%eax
add    $0x12,%eax
mov    %eax,-0x1c(%rbp)
jmp    1319 <process_buffer+0x1c9>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x80,%eax
jne    130b <process_buffer+0x1bb>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
lea    -0x38(%rbp),%r9
call   1030 <decode_short_entry@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    -0x48(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x50(%rbp),%r9
call   1070 <ecef_to_geo@plt>
cmpq   $0x0,-0x60(%rbp)
jle    12e2 <process_buffer+0x192>
mov    -0x28(%rbp),%rax
mov    -0x60(%rbp),%rcx
add    $0xe10,%rcx
cmp    %rcx,%rax
jle    12e2 <process_buffer+0x192>
lea    0xd39(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
mov    -0x38(%rbp),%esi
call   1040 <output_gpx_trk_point@plt>
mov    -0x1c(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x1c(%rbp)
jmp    1314 <process_buffer+0x1c4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1319 <process_buffer+0x1c9>
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    1185 <process_buffer+0x35>
mov    -0x60(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe93(%rip),%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
jle    12d6 <process_buffer+0x186>
xor    %r15d,%r15d
lea    0x30(%rsp),%r12
lea    0x28(%rsp),%r13
jmp    11c6 <process_buffer+0x76>
nopl   0x0(%rax)
mov    0x18(%rsp),%rdi
movsd  0x30(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
mov    0x8(%rsp),%esi
call   1050 <output_gpx_trk_point@plt>
mov    $0x12,%eax
add    %eax,%r15d
mov    0x18(%rsp),%r14
cmp    %ebp,%r15d
jge    12d6 <process_buffer+0x186>
mov    %r15d,%eax
lea    (%rbx,%rax,1),%rdi
movzbl (%rbx,%rax,1),%ecx
test   $0x40,%cl
jne    1270 <process_buffer+0x120>
mov    $0x1,%eax
cmp    $0x80,%cl
jne    11b5 <process_buffer+0x65>
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
call   1030 <decode_short_entry@plt>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0x20(%rsp),%rcx
mov    %r12,%r8
mov    %r13,%r9
call   1070 <ecef_to_geo@plt>
test   %r14,%r14
jle    123d <process_buffer+0xed>
add    $0xe10,%r14
cmp    %r14,0x18(%rsp)
jle    123d <process_buffer+0xed>
lea    0xddd(%rip),%rdi
call   1040 <puts@plt>
mov    0x18(%rsp),%rdi
movsd  0x30(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
mov    0x8(%rsp),%esi
call   1050 <output_gpx_trk_point@plt>
mov    $0x8,%eax
jmp    11b5 <process_buffer+0x65>
nopw   0x0(%rax,%rax,1)
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
call   1060 <decode_long_entry@plt>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0x20(%rsp),%rcx
mov    %r12,%r8
mov    %r13,%r9
call   1070 <ecef_to_geo@plt>
test   %r14,%r14
jle    1190 <process_buffer+0x40>
add    $0xe10,%r14
cmp    %r14,0x18(%rsp)
jle    1190 <process_buffer+0x40>
lea    0xd49(%rip),%rdi
call   1040 <puts@plt>
jmp    1190 <process_buffer+0x40>
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"<!-- next sector -->\0A\00"
@.str.1 = [20 x i8] c"</trkseg>\0A<trkseg>\0A\00"
define i64 @process_buffer(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca i32
%17 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
store i32 0, i32* %7
store i32 0, i32* %16
%18 = load i64, i64* %6
store i64 %18, i64* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %111, %3
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %113
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = and i32 %30, 64
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %71
33: ; preds = %24
%34 = load i8*, i8** %4
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = call i32 @decode_long_entry(i8* %37, i64* %8, i32* %9, i32* %10, i32* %11, i32* %12)
%39 = load i32, i32* %9
%40 = load i32, i32* %10
%41 = load i32, i32* %11
%42 = call i32 @ecef_to_geo(i32 %39, i32 %40, i32 %41, double* %14, double* %13, double* %15)
%43 = load i8*, i8** %4
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = and i32 %48, 32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %33
store i32 1, i32* %16
br label %52
52: ; preds = %51, %33
%53 = load i64, i64* %17
%54 = icmp sgt i64 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %52
%56 = load i64, i64* %8
%57 = load i64, i64* %17
%58 = add nsw i64 %57, 3600
%59 = icmp sgt i64 %56, %58
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %62
62: ; preds = %60, %55, %52
%63 = load i64, i64* %8
%64 = load double, double* %13
%65 = load double, double* %14
%66 = load double, double* %15
%67 = load i32, i32* %12
%68 = call i32 @output_gpx_trk_point(i64 %63, double %64, double %65, double %66, i32 %67)
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 18
store i32 %70, i32* %7
br label %111
71: ; preds = %24
%72 = load i8*, i8** %4
%73 = load i32, i32* %7
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8, i8* %75
%77 = zext i8 %76 to i32
%78 = icmp eq i32 %77, 128
br i1 %78, label %79, label %107
79: ; preds = %71
%80 = load i8*, i8** %4
%81 = load i32, i32* %7
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = call i32 @decode_short_entry(i8* %83, i64* %8, i32* %9, i32* %10, i32* %11, i32* %12)
%85 = load i32, i32* %9
%86 = load i32, i32* %10
%87 = load i32, i32* %11
%88 = call i32 @ecef_to_geo(i32 %85, i32 %86, i32 %87, double* %14, double* %13, double* %15)
%89 = load i64, i64* %17
%90 = icmp sgt i64 %89, 0
br i1 %90, label %91, label %98
91: ; preds = %79
%92 = load i64, i64* %8
%93 = load i64, i64* %17
%94 = add nsw i64 %93, 3600
%95 = icmp sgt i64 %92, %94
br i1 %95, label %96, label %98
96: ; preds = %91
%97 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %98
98: ; preds = %96, %91, %79
%99 = load i64, i64* %8
%100 = load double, double* %13
%101 = load double, double* %14
%102 = load double, double* %15
%103 = load i32, i32* %12
%104 = call i32 @output_gpx_trk_point(i64 %99, double %100, double %101, double %102, i32 %103)
%105 = load i32, i32* %7
%106 = add nsw i32 %105, 8
store i32 %106, i32* %7
br label %110
107: ; preds = %71
%108 = load i32, i32* %7
%109 = add nsw i32 %108, 1
store i32 %109, i32* %7
br label %110
110: ; preds = %107, %98
br label %111
111: ; preds = %110, %62
%112 = load i64, i64* %8
store i64 %112, i64* %17
br label %20
113: ; preds = %20
%114 = load i64, i64* %17
ret i64 %114
}

LLVM IR (-O2):
@str = [21 x i8] c"<!-- next sector -->\00"
@str.3 = [19 x i8] c"</trkseg>\0A<trkseg>\00"
define i64 @process_buffer(i8* %0, i32 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = bitcast i64* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %6 to i8*
%15 = bitcast i32* %7 to i8*
%16 = bitcast i32* %8 to i8*
%17 = bitcast double* %9 to i8*
%18 = bitcast double* %10 to i8*
%19 = bitcast double* %11 to i8*
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%21 = icmp sgt i32 %1, 0
br i1 %21, label %22, label %77
22: ; preds = %3, %72
%23 = phi i64 [ %75, %72 ], [ %2, %3 ]
%24 = phi i32 [ %74, %72 ], [ 0, %3 ]
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = load i8, i8* %26
%28 = and i8 %27, 64
%29 = icmp eq i8 %28, 0
br i1 %29, label %50, label %30
30: ; preds = %22
%31 = call i32 @decode_long_entry(i8* %26, i64* %4, i32* %5, i32* %6, i32* %7, i32* %8)
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i32 @ecef_to_geo(i32 %32, i32 %33, i32 %34, double* %10, double* %9, double* %11)
%36 = icmp sgt i64 %23, 0
br i1 %36, label %37, label %43
37: ; preds = %30
%38 = load i64, i64* %4
%39 = add nuw nsw i64 %23, 3600
%40 = icmp sgt i64 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %37, %30
%44 = load i64, i64* %4
%45 = load double, double* %9
%46 = load double, double* %10
%47 = load double, double* %11
%48 = load i32, i32* %8
%49 = call i32 @output_gpx_trk_point(i64 %44, double %45, double %46, double %47, i32 %48)
br label %72
50: ; preds = %22
%51 = icmp eq i8 %27, -128
br i1 %51, label %52, label %72
52: ; preds = %50
%53 = call i32 @decode_short_entry(i8* %26, i64* %4, i32* %5, i32* %6, i32* %7, i32* %8)
%54 = load i32, i32* %5
%55 = load i32, i32* %6
%56 = load i32, i32* %7
%57 = call i32 @ecef_to_geo(i32 %54, i32 %55, i32 %56, double* %10, double* %9, double* %11)
%58 = icmp sgt i64 %23, 0
br i1 %58, label %59, label %65
59: ; preds = %52
%60 = load i64, i64* %4
%61 = add nuw nsw i64 %23, 3600
%62 = icmp sgt i64 %60, %61
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
br label %65
65: ; preds = %63, %59, %52
%66 = load i64, i64* %4
%67 = load double, double* %9
%68 = load double, double* %10
%69 = load double, double* %11
%70 = load i32, i32* %8
%71 = call i32 @output_gpx_trk_point(i64 %66, double %67, double %68, double %69, i32 %70)
br label %72
72: ; preds = %50, %65, %43
%73 = phi i32 [ 8, %65 ], [ 18, %43 ], [ 1, %50 ]
%74 = add nuw nsw i32 %24, %73
%75 = load i64, i64* %4
%76 = icmp slt i32 %74, %1
br i1 %76, label %22, label %77
77: ; preds = %72, %3
%78 = phi i64 [ %2, %3 ], [ %75, %72 ]
ret i64 %78
}