#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 */
double atof(char const *);
int /*<<< orphan*/ isalpha(char const);
scalar_t__ isdigit(char const);
double unitfactor(char const *);
int psdimension(const char *what, int *dim) {
  const char *unit;
  int dot = 0;
  if (!what || !*what)
    return -1;
  if (*(unit = what) == '-')
    ++unit;
  for (; isdigit(*unit) || (*unit == '.' && !dot++); ++unit)
    ;
  if (*unit && !isalpha(*unit)) {
    return -1;
  } else {
    double base = atof(what);
    double factor = unitfactor(unit);
    if (factor) {
      *dim = base * factor * 72;
      return 0;
    }
    return 1;
  }
}


x86 assembly (clang, -O0):
<psdimension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116f <psdimension+0x2f>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    117b <psdimension+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b2 <psdimension+0x172>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    119b <psdimension+0x5b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a0 <psdimension+0x60>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x39(%rbp)
jne    11ef <psdimension+0xaf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x3a(%rbp)
jne    11e9 <psdimension+0xa9>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11ff <psdimension+0xbf>
jmp    1215 <psdimension+0xd5>
jmp    1204 <psdimension+0xc4>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a0 <psdimension+0x60>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1246 <psdimension+0x106>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%eax
jne    1246 <psdimension+0x106>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b2 <psdimension+0x172>
mov    -0x10(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <unitfactor@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    127f <psdimension+0x13f>
jp     127f <psdimension+0x13f>
jmp    12ab <psdimension+0x16b>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  0xd6f(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    12b2 <psdimension+0x172>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psdimension>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     11f7 <psdimension+0xb7>
mov    %rdi,%r12
mov    (%rdi),%al
test   %al,%al
je     11f7 <psdimension+0xb7>
mov    %rsi,%r14
mov    %r12,%rbx
cmp    $0x2d,%al
jne    1177 <psdimension+0x37>
lea    0x1(%r12),%rbx
xor    %ebp,%ebp
jmp    1184 <psdimension+0x44>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1180 <psdimension+0x40>
movzbl (%rbx),%eax
cmp    $0x2e,%al
jne    11a1 <psdimension+0x61>
test   %ebp,%ebp
mov    $0x1,%ebp
je     1180 <psdimension+0x40>
test   %al,%al
je     11b1 <psdimension+0x71>
movsbl %al,%edi
call   1060 <isalpha@plt>
test   %eax,%eax
je     11f7 <psdimension+0xb7>
mov    %r12,%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <unitfactor@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d3 <psdimension+0x93>
jnp    11f1 <psdimension+0xb1>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  0xe1b(%rip),%xmm1
cvttsd2si %xmm1,%eax
mov    %eax,(%r14)
xor    %r15d,%r15d
jmp    11f7 <psdimension+0xb7>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @psdimension(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %7
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %12, %2
store i32 -1, i32* %3
br label %75
17: ; preds = %12
%18 = load i8*, i8** %4
store i8* %18, i8** %6
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 45
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %6
br label %25
25: ; preds = %22, %17
br label %26
26: ; preds = %46, %25
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = call i64 @isdigit(i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %43, label %31
31: ; preds = %26
%32 = load i8*, i8** %6
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 46
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
%39 = icmp ne i32 %37, 0
%40 = xor i1 %39, true
br label %41
41: ; preds = %36, %31
%42 = phi i1 [ false, %31 ], [ %40, %36 ]
br label %43
43: ; preds = %41, %26
%44 = phi i1 [ true, %26 ], [ %42, %41 ]
br i1 %44, label %45, label %49
45: ; preds = %43
br label %46
46: ; preds = %45
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %6
br label %26
49: ; preds = %43
%50 = load i8*, i8** %6
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = load i8*, i8** %6
%56 = load i8, i8* %55
%57 = call i32 @isalpha(i8 signext %56)
%58 = icmp ne i32 %57, 0
br i1 %58, label %60, label %59
59: ; preds = %54
store i32 -1, i32* %3
br label %75
60: ; preds = %54, %49
%61 = load i8*, i8** %4
%62 = call double @atof(i8* %61)
store double %62, double* %8
%63 = load i8*, i8** %6
%64 = call double @unitfactor(i8* %63)
store double %64, double* %9
%65 = load double, double* %9
%66 = fcmp une double %65, 0.000000e+00
br i1 %66, label %67, label %74
67: ; preds = %60
%68 = load double, double* %8
%69 = load double, double* %9
%70 = fmul double %68, %69
%71 = fmul double %70, 7.200000e+01
%72 = fptosi double %71 to i32
%73 = load i32*, i32** %5
store i32 %72, i32* %73
store i32 0, i32* %3
br label %75
74: ; preds = %60
store i32 1, i32* %3
br label %75
75: ; preds = %74, %67, %59, %16
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
define i32 @psdimension(i8* %0, i32* nocapture writeonly %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %37, label %4
4: ; preds = %2
%5 = load i8, i8* %0
switch i8 %5, label %8 [
i8 0, label %37
i8 45, label %6
]
6: ; preds = %4
%7 = getelementptr inbounds i8, i8* %0, i64 1
br label %8
8: ; preds = %4, %6
%9 = phi i8* [ %7, %6 ], [ %0, %4 ]
br label %10
10: ; preds = %8, %21
%11 = phi i32 [ %22, %21 ], [ 0, %8 ]
%12 = phi i8* [ %23, %21 ], [ %9, %8 ]
%13 = load i8, i8* %12
%14 = tail call i64 @isdigit(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i8, i8* %12
%18 = icmp eq i8 %17, 46
%19 = icmp eq i32 %11, 0
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %21, label %24
21: ; preds = %16, %10
%22 = phi i32 [ %11, %10 ], [ 1, %16 ]
%23 = getelementptr inbounds i8, i8* %12, i64 1
br label %10
24: ; preds = %16
%25 = icmp eq i8 %17, 0
br i1 %25, label %29, label %26
26: ; preds = %24
%27 = tail call i32 @isalpha(i8 signext %17)
%28 = icmp eq i32 %27, 0
br i1 %28, label %37, label %29
29: ; preds = %26, %24
%30 = tail call double @atof(i8* %0)
%31 = tail call double @unitfactor(i8* %12)
%32 = fcmp une double %31, 0.000000e+00
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = fmul double %30, %31
%35 = fmul double %34, 7.200000e+01
%36 = fptosi double %35 to i32
store i32 %36, i32* %1
br label %37
37: ; preds = %33, %29, %26, %4, %2
%38 = phi i32 [ -1, %4 ], [ -1, %2 ], [ -1, %26 ], [ 0, %33 ], [ 1, %29 ]
ret i32 %38
}