#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int fscanf(int /*<<< orphan*/ *, char *, double *);
char *readlabel(int /*<<< orphan*/ *);
int /*<<< orphan*/ skipspace(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
char *readlabelandweight(FILE *fp, double *weight, int *error) {
  char *answer;
  int ch;
  *weight = 0;
  answer = readlabel(fp);
  if (!answer) {
    *error = -1;
    return 0;
  }
  skipspace(fp);
  ch = fgetc(fp);
  if (ch == ':') {
    if (fscanf(fp, "%lf", weight) != 1) {
      *error = -2;
      free(answer);
      return 0;
    }
  } else {
    ungetc(ch, fp);
  }
  if (*answer == 0) {
    free(answer);
    answer = 0;
  }
  *error = 0;
  return answer;
}


x86 assembly (clang, -O0):
<readlabelandweight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rdi
call   1060 <readlabel@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ae <readlabelandweight+0x4e>
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    124e <readlabelandweight+0xee>
mov    -0x10(%rbp),%rdi
call   1080 <skipspace@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x3a,-0x2c(%rbp)
jne    120f <readlabelandweight+0xaf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     120a <readlabelandweight+0xaa>
mov    -0x20(%rbp),%rax
movl   $0xfffffffe,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    124e <readlabelandweight+0xee>
jmp    121b <readlabelandweight+0xbb>
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <ungetc@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    123c <readlabelandweight+0xdc>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readlabelandweight>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
movq   $0x0,(%rsi)
call   1060 <readlabel@plt>
test   %rax,%rax
je     11c5 <readlabelandweight+0x65>
mov    %rax,%r15
mov    %rbx,%rdi
call   1080 <skipspace@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0x3a,%eax
jne    11d1 <readlabelandweight+0x71>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11db <readlabelandweight+0x7b>
movl   $0xfffffffe,(%r14)
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
jmp    11f3 <readlabelandweight+0x93>
movl   $0xffffffff,(%r14)
xor    %r15d,%r15d
jmp    11f3 <readlabelandweight+0x93>
mov    %eax,%edi
mov    %rbx,%rsi
call   1070 <ungetc@plt>
cmpb   $0x0,(%r15)
jne    11ec <readlabelandweight+0x8c>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
movl   $0x0,(%r14)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define i8* @readlabelandweight(i32* %0, double* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca double*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %5
store double* %1, double** %6
store i32* %2, i32** %7
%10 = load double*, double** %6
store double 0.000000e+00, double* %10
%11 = load i32*, i32** %5
%12 = call i8* @readlabel(i32* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = load i32*, i32** %7
store i32 -1, i32* %16
store i8* null, i8** %4
br label %49
17: ; preds = %3
%18 = load i32*, i32** %5
%19 = call i32 @skipspace(i32* %18)
%20 = load i32*, i32** %5
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp eq i32 %22, 58
br i1 %23, label %24, label %34
24: ; preds = %17
%25 = load i32*, i32** %5
%26 = load double*, double** %6
%27 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %26)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32*, i32** %7
store i32 -2, i32* %30
%31 = load i8*, i8** %8
%32 = call i32 @free(i8* %31)
store i8* null, i8** %4
br label %49
33: ; preds = %24
br label %38
34: ; preds = %17
%35 = load i32, i32* %9
%36 = load i32*, i32** %5
%37 = call i32 @ungetc(i32 %35, i32* %36)
br label %38
38: ; preds = %34, %33
%39 = load i8*, i8** %8
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
store i8* null, i8** %8
br label %46
46: ; preds = %43, %38
%47 = load i32*, i32** %7
store i32 0, i32* %47
%48 = load i8*, i8** %8
store i8* %48, i8** %4
br label %49
49: ; preds = %46, %29, %15
%50 = load i8*, i8** %4
ret i8* %50
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define i8* @readlabelandweight(i32* %0, double* %1, i32* nocapture writeonly %2) {
store double 0.000000e+00, double* %1
%4 = tail call i8* @readlabel(i32* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %3
store i32 -1, i32* %2
br label %25
7: ; preds = %3
%8 = tail call i32 @skipspace(i32* %0)
%9 = tail call i32 @fgetc(i32* %0)
%10 = icmp eq i32 %9, 58
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %18, label %14
14: ; preds = %11
store i32 -2, i32* %2
%15 = tail call i32 @free(i8* %4)
br label %25
16: ; preds = %7
%17 = tail call i32 @ungetc(i32 %9, i32* %0)
br label %18
18: ; preds = %11, %16
%19 = load i8, i8* %4
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @free(i8* %4)
br label %23
23: ; preds = %21, %18
%24 = phi i8* [ null, %21 ], [ %4, %18 ]
store i32 0, i32* %2
br label %25
25: ; preds = %23, %14, %6
%26 = phi i8* [ null, %14 ], [ %24, %23 ], [ null, %6 ]
ret i8* %26
}