#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*/ parse_unit_factor(char *, unsigned long *);
long strtol(char const *, char **, int /*<<< orphan*/);
int perf_parse_long(const char *value, long *ret) {
  if (value && *value) {
    char *end;
    long val = strtol(value, &end, 0);
    unsigned long factor = 1;
    if (!parse_unit_factor(end, &factor))
      return 0;
    *ret = val * factor;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<perf_parse_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a4 <perf_parse_long+0x84>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a4 <perf_parse_long+0x84>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <parse_unit_factor@plt>
cmp    $0x0,%eax
jne    1188 <perf_parse_long+0x68>
movl   $0x0,-0x4(%rbp)
jmp    11ab <perf_parse_long+0x8b>
mov    -0x28(%rbp),%rcx
imul   -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11ab <perf_parse_long+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perf_parse_long>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
test   %rdi,%rdi
je     116f <perf_parse_long+0x4f>
cmpb   $0x0,(%rdi)
je     116f <perf_parse_long+0x4f>
mov    %rsi,%r14
lea    0x8(%rsp),%rsi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,%r15
movq   $0x1,(%rsp)
mov    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <parse_unit_factor@plt>
test   %eax,%eax
je     116f <perf_parse_long+0x4f>
imul   (%rsp),%r15
mov    %r15,(%r14)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @perf_parse_long(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %28
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = call i64 @strtol(i8* %17, i8** %6, i32 0)
store i64 %18, i64* %7
store i64 1, i64* %8
%19 = load i8*, i8** %6
%20 = call i32 @parse_unit_factor(i8* %19, i64* %8)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %16
store i32 0, i32* %3
br label %29
23: ; preds = %16
%24 = load i64, i64* %7
%25 = load i64, i64* %8
%26 = mul i64 %24, %25
%27 = load i64*, i64** %5
store i64 %26, i64* %27
store i32 1, i32* %3
br label %29
28: ; preds = %11, %2
store i32 0, i32* %3
br label %29
29: ; preds = %28, %23, %22
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @perf_parse_long(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = icmp eq i8* %0, null
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %6
%10 = bitcast i8** %3 to i8*
%11 = call i64 @strtol(i8* %0, i8** %3, i32 0)
%12 = bitcast i64* %4 to i8*
store i64 1, i64* %4
%13 = load i8*, i8** %3
%14 = call i32 @parse_unit_factor(i8* %13, i64* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %9
%17 = load i64, i64* %4
%18 = mul i64 %17, %11
store i64 %18, i64* %1
br label %19
19: ; preds = %9, %16
%20 = phi i32 [ 1, %16 ], [ 0, %9 ]
br label %21
21: ; preds = %2, %6, %19
%22 = phi i32 [ %20, %19 ], [ 0, %6 ], [ 0, %2 ]
ret i32 %22
}