#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*/ printf(char *, ...);
int sg_trama_cambio_read(int, unsigned char *);
int chronopic_get_trama_cambio(int fd, double *t, int *estado) {
  int n;
  unsigned char trama[10];
  n = sg_trama_cambio_read(fd, trama);
  if (n != 1)
    return n;
  printf("%c-%d-%d-%d-%d", trama[0], trama[1], trama[2], trama[3], trama[4]);
  printf("%d", ((trama[2] * 65536 + trama[3] * 256 + trama[4]) * 8) / 1000);
  if (trama[0] != 'X') {
    printf("Error. Trama desconocida\n");
    return -1;
  }
  if (trama[1] != 0 && trama[1] != 1) {
    printf("Error. Estado no valido\n");
    return -1;
  }
  *estado = (int)(trama[1] & 0xff);
  *t = (double)((trama[2] * 65536 + trama[3] * 256 + trama[4]) * 8) / 1000;
  printf("%f", *t);
  return 1;
}


x86 assembly (clang, -O0):
<chronopic_get_trama_cambio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x26(%rbp),%rsi
call   1040 <sg_trama_cambio_read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     1157 <chronopic_get_trama_cambio+0x37>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <chronopic_get_trama_cambio+0x145>
movzbl -0x26(%rbp),%esi
movzbl -0x25(%rbp),%edx
movzbl -0x24(%rbp),%ecx
movzbl -0x23(%rbp),%r8d
movzbl -0x22(%rbp),%r9d
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x24(%rbp),%eax
shl    $0x10,%eax
movzbl -0x23(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0x22(%rbp),%ecx
add    %ecx,%eax
shl    $0x3,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x26(%rbp),%eax
cmp    $0x58,%eax
je     11d3 <chronopic_get_trama_cambio+0xb3>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1265 <chronopic_get_trama_cambio+0x145>
movzbl -0x25(%rbp),%eax
cmp    $0x0,%eax
je     1207 <chronopic_get_trama_cambio+0xe7>
movzbl -0x25(%rbp),%eax
cmp    $0x1,%eax
je     1207 <chronopic_get_trama_cambio+0xe7>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1265 <chronopic_get_trama_cambio+0x145>
movzbl -0x25(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x24(%rbp),%eax
shl    $0x10,%eax
movzbl -0x23(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0x22(%rbp),%ecx
add    %ecx,%eax
shl    $0x3,%eax
cvtsi2sd %eax,%xmm0
movsd  0xdc4(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xdf3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chronopic_get_trama_cambio>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0xe(%rsp),%rsi
call   1050 <sg_trama_cambio_read@plt>
cmp    $0x1,%eax
jne    121a <chronopic_get_trama_cambio+0xea>
movzbl 0xe(%rsp),%esi
movzbl 0xf(%rsp),%edx
movzbl 0x10(%rsp),%ecx
movzbl 0x11(%rsp),%r8d
movzbl 0x12(%rsp),%r9d
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x10(%rsp),%eax
shl    $0x10,%eax
movzbl 0x11(%rsp),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movzbl 0x12(%rsp),%eax
or     %ecx,%eax
imul   $0x10624dd3,%rax,%rsi
shr    $0x23,%rsi
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpb   $0x58,0xe(%rsp)
jne    1200 <chronopic_get_trama_cambio+0xd0>
movzbl 0xf(%rsp),%eax
cmp    $0x2,%eax
jae    1209 <chronopic_get_trama_cambio+0xd9>
mov    %eax,(%rbx)
movzbl 0x10(%rsp),%eax
shl    $0x10,%eax
movzbl 0x11(%rsp),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movzbl 0x12(%rsp),%eax
or     %ecx,%eax
shl    $0x3,%eax
cvtsi2sd %eax,%xmm0
divsd  0xe1a(%rip),%xmm0
movsd  %xmm0,(%r14)
lea    0xe25(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    121a <chronopic_get_trama_cambio+0xea>
lea    0xe2b(%rip),%rdi
jmp    1210 <chronopic_get_trama_cambio+0xe0>
lea    0xe0a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%c-%d-%d-%d-%d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"Error. Trama desconocida\0A\00"
@.str.3 = [25 x i8] c"Error. Estado no valido\0A\00"
@.str.4 = [3 x i8] c"%f\00"
define i32 @chronopic_get_trama_cambio(i32 %0, double* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [10 x i8]
store i32 %0, i32* %5
store double* %1, double** %6
store i32* %2, i32** %7
%10 = load i32, i32* %5
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%12 = call i32 @sg_trama_cambio_read(i32 %10, i8* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %8
store i32 %16, i32* %4
br label %94
17: ; preds = %3
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 1
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 2
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 3
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 4
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %23, i32 %26, i32 %29, i32 %32)
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 2
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = mul nsw i32 %36, 65536
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 3
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = mul nsw i32 %40, 256
%42 = add nsw i32 %37, %41
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 4
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = add nsw i32 %42, %45
%47 = mul nsw i32 %46, 8
%48 = sdiv i32 %47, 1000
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = icmp ne i32 %52, 88
br i1 %53, label %54, label %56
54: ; preds = %17
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %94
56: ; preds = %17
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 1
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %56
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 1
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = icmp ne i32 %64, 1
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %4
br label %94
68: ; preds = %61, %56
%69 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 1
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = and i32 %71, 255
%73 = load i32*, i32** %7
store i32 %72, i32* %73
%74 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 2
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = mul nsw i32 %76, 65536
%78 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 3
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = mul nsw i32 %80, 256
%82 = add nsw i32 %77, %81
%83 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 4
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = add nsw i32 %82, %85
%87 = mul nsw i32 %86, 8
%88 = sitofp i32 %87 to double
%89 = fdiv double %88, 1.000000e+03
%90 = load double*, double** %6
store double %89, double* %90
%91 = load double*, double** %6
%92 = load double, double* %91
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), double %92)
store i32 1, i32* %4
br label %94
94: ; preds = %68, %66, %54, %15
%95 = load i32, i32* %4
ret i32 %95
}

LLVM IR (-O2):
@.str = [15 x i8] c"%c-%d-%d-%d-%d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c"%f\00"
@str = [24 x i8] c"Error. Estado no valido\00"
@str.5 = [25 x i8] c"Error. Trama desconocida\00"
define i32 @chronopic_get_trama_cambio(i32 %0, double* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%6 = call i32 @sg_trama_cambio_read(i32 %0, i8* %5)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %61
8: ; preds = %3
%9 = load i8, i8* %5
%10 = zext i8 %9 to i32
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 1
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 2
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 3
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 4
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %16, i32 %19, i32 %22)
%24 = load i8, i8* %14
%25 = zext i8 %24 to i32
%26 = shl nuw nsw i32 %25, 16
%27 = load i8, i8* %17
%28 = zext i8 %27 to i32
%29 = shl nuw nsw i32 %28, 8
%30 = or i32 %29, %26
%31 = load i8, i8* %20
%32 = zext i8 %31 to i32
%33 = or i32 %30, %32
%34 = udiv i32 %33, 125
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i8, i8* %5
%37 = icmp eq i8 %36, 88
br i1 %37, label %40, label %38
38: ; preds = %8
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
br label %61
40: ; preds = %8
%41 = load i8, i8* %11
%42 = icmp ult i8 %41, 2
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %61
45: ; preds = %40
%46 = zext i8 %41 to i32
store i32 %46, i32* %2
%47 = load i8, i8* %14
%48 = zext i8 %47 to i32
%49 = shl nuw nsw i32 %48, 16
%50 = load i8, i8* %17
%51 = zext i8 %50 to i32
%52 = shl nuw nsw i32 %51, 8
%53 = or i32 %52, %49
%54 = load i8, i8* %20
%55 = zext i8 %54 to i32
%56 = or i32 %53, %55
%57 = shl nuw nsw i32 %56, 3
%58 = sitofp i32 %57 to double
%59 = fdiv double %58, 1.000000e+03
store double %59, double* %1
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), double %59)
br label %61
61: ; preds = %3, %45, %43, %38
%62 = phi i32 [ -1, %38 ], [ -1, %43 ], [ 1, %45 ], [ %6, %3 ]
ret i32 %62
}