#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 */
scalar_t__ strcmp(char const *, char *);
double strtod(char const *, char **);
int hpgs_parse_length(const char *str, double *pt_length) {
  const char *unit = "pt";
  char *endptr = (char *)str;
  *pt_length = strtod(str, &endptr);
  if (endptr == str)
    return -1;
  if (*endptr)
    unit = endptr;
  if (strcmp(unit, "cm") == 0) {
    *pt_length *= 72.0 / 2.54;
  } else if (strcmp(unit, "mm") == 0) {
    *pt_length *= 72.0 / 25.4;
  } else if (strcmp(unit, "m") == 0) {
    *pt_length *= 72.0 / 0.0254;
  } else if (strcmp(unit, "inch") == 0) {
    *pt_length *= 72.0;
  } else if (strcmp(unit, "pt"))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<hpgs_parse_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xee9(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1172 <hpgs_parse_length+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1294 <hpgs_parse_length+0x174>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     1187 <hpgs_parse_length+0x67>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ba <hpgs_parse_length+0x9a>
mov    -0x18(%rbp),%rax
movsd  0xe6b(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    128d <hpgs_parse_length+0x16d>
mov    -0x20(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ed <hpgs_parse_length+0xcd>
mov    -0x18(%rbp),%rax
movsd  0xe30(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    1288 <hpgs_parse_length+0x168>
mov    -0x20(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1220 <hpgs_parse_length+0x100>
mov    -0x18(%rbp),%rax
movsd  0xdf5(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    1283 <hpgs_parse_length+0x163>
mov    -0x20(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1253 <hpgs_parse_length+0x133>
mov    -0x18(%rbp),%rax
movsd  0xdba(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    127e <hpgs_parse_length+0x15e>
mov    -0x20(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1279 <hpgs_parse_length+0x159>
movl   $0xffffffff,-0x4(%rbp)
jmp    1294 <hpgs_parse_length+0x174>
jmp    127e <hpgs_parse_length+0x15e>
jmp    1283 <hpgs_parse_length+0x163>
jmp    1288 <hpgs_parse_length+0x168>
jmp    128d <hpgs_parse_length+0x16d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpgs_parse_length>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,(%rbx)
mov    0x8(%rsp),%rax
mov    $0xffffffff,%r14d
cmp    %rbp,%rax
je     11fa <hpgs_parse_length+0xda>
cmpb   $0x0,(%rax)
lea    0xec1(%rip),%rbp
cmovne %rax,%rbp
lea    0xeb9(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11c9 <hpgs_parse_length+0xa9>
lea    0xea8(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d3 <hpgs_parse_length+0xb3>
lea    0xe92(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11dd <hpgs_parse_length+0xbd>
lea    0xe83(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e7 <hpgs_parse_length+0xc7>
lea    0xe66(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11fa <hpgs_parse_length+0xda>
jmp    11f7 <hpgs_parse_length+0xd7>
movsd  0xe2f(%rip),%xmm0
jmp    11ef <hpgs_parse_length+0xcf>
movsd  0xe2d(%rip),%xmm0
jmp    11ef <hpgs_parse_length+0xcf>
movsd  0xe2b(%rip),%xmm0
jmp    11ef <hpgs_parse_length+0xcf>
movsd  0xe29(%rip),%xmm0
mulsd  (%rbx),%xmm0
movsd  %xmm0,(%rbx)
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"pt\00"
@.str.1 = [3 x i8] c"cm\00"
@.str.2 = [3 x i8] c"mm\00"
@.str.3 = [2 x i8] c"m\00"
@.str.4 = [5 x i8] c"inch\00"
define i32 @hpgs_parse_length(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store double* %1, double** %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
%9 = load i8*, i8** %4
%10 = call double @strtod(i8* %9, i8** %7)
%11 = load double*, double** %5
store double %10, double* %11
%12 = load i8*, i8** %7
%13 = load i8*, i8** %4
%14 = icmp eq i8* %12, %13
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %64
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i8*, i8** %7
store i8* %21, i8** %6
br label %22
22: ; preds = %20, %16
%23 = load i8*, i8** %6
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load double*, double** %5
%28 = load double, double* %27
%29 = fmul double %28, 0x403C58B162C58B16
store double %29, double* %27
br label %63
30: ; preds = %22
%31 = load i8*, i8** %6
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load double*, double** %5
%36 = load double, double* %35
%37 = fmul double %36, 0x4006AD5AB56AD5AC
store double %37, double* %35
br label %62
38: ; preds = %30
%39 = load i8*, i8** %6
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load double*, double** %5
%44 = load double, double* %43
%45 = fmul double %44, 0x40A6254A952A54AA
store double %45, double* %43
br label %61
46: ; preds = %38
%47 = load i8*, i8** %6
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = load double*, double** %5
%52 = load double, double* %51
%53 = fmul double %52, 7.200000e+01
store double %53, double* %51
br label %60
54: ; preds = %46
%55 = load i8*, i8** %6
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %54
store i32 -1, i32* %3
br label %64
59: ; preds = %54
br label %60
60: ; preds = %59, %50
br label %61
61: ; preds = %60, %42
br label %62
62: ; preds = %61, %34
br label %63
63: ; preds = %62, %26
store i32 0, i32* %3
br label %64
64: ; preds = %63, %58, %15
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [3 x i8] c"pt\00"
@.str.1 = [3 x i8] c"cm\00"
@.str.2 = [3 x i8] c"mm\00"
@.str.3 = [2 x i8] c"m\00"
@.str.4 = [5 x i8] c"inch\00"
define i32 @hpgs_parse_length(i8* %0, double* nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
%5 = call double @strtod(i8* %0, i8** %3)
store double %5, double* %1
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
br i1 %7, label %31, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %8
%15 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %30, label %31
26: ; preds = %20, %17, %14, %8
%27 = phi double [ 0x403C58B162C58B16, %8 ], [ 0x4006AD5AB56AD5AC, %14 ], [ 0x40A6254A952A54AA, %17 ], [ 7.200000e+01, %20 ]
%28 = load double, double* %1
%29 = fmul double %28, %27
store double %29, double* %1
br label %30
30: ; preds = %26, %23
br label %31
31: ; preds = %23, %2, %30
%32 = phi i32 [ 0, %30 ], [ -1, %2 ], [ -1, %23 ]
ret i32 %32
}