#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 atoi(char *);
int /*<<< orphan*/ is_a_number(char *);
int /*<<< orphan*/ my_assert_always(int);
int /*<<< orphan*/ my_errorf(char *, int, int, ...);
int strlen(char *);
int facname_to_factor(char *facname, int line, int i) {
  int len = (int)strlen(facname);
  int factor = -77;
  if (len == 0) {
    my_errorf("facname_to_factor: empty facname on line %d pos %d, but how?",
              line, i);
  }
  if (len > 2 && facname[len - 2] == ':') {
    if (facname[len - 1] != '1') {
      my_errorf("factor %d on line %d (%s) has : but is not followed by 1.",
                i + 1, line, facname);
    }
    facname[len - 2] = '\0';
  }
  if (!is_a_number(facname)) {
    my_errorf("factors should all be of the form <number> or <number>:1 but\n"
              " factor number %d on line %d has the following before the "
              "\":1\":\n\"%s\"\n",
              i + 1, line, facname);
  }
  factor = atoi(facname);
  if (factor < 0)
    my_errorf("factor "
              "number %d on line %d has value %d which is crazy\n",
              i + 1, line, factor);
  if (strlen(facname) != len) {
    if (strlen(facname) != len - 2) {
      my_errorf("facname_to_factor: internal error: len craziness on factor "
                "%d, line %d, facname %s",
                i + 1, line, facname);
    }
    facname[len - 2] = ':';
  }
  my_assert_always(factor >= 0);
  return factor;
}


x86 assembly (clang, -O0):
<facname_to_factor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0xffffffb3,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1193 <facname_to_factor+0x43>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <my_errorf@plt>
cmpl   $0x2,-0x14(%rbp)
jle    11fd <facname_to_factor+0xad>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    11fd <facname_to_factor+0xad>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
je     11ec <facname_to_factor+0x9c>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <my_errorf@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1050 <is_a_number@plt>
cmp    $0x0,%eax
jne    122a <facname_to_factor+0xda>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <my_errorf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    125a <facname_to_factor+0x10a>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <my_errorf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x14(%rbp),%eax
je     12af <facname_to_factor+0x15f>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
je     129e <facname_to_factor+0x14e>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <my_errorf@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x3a,(%rax,%rcx,1)
cmpl   $0x0,-0x18(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <my_assert_always@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<facname_to_factor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    %eax,%r12d
test   %eax,%eax
je     11b0 <facname_to_factor+0x60>
cmp    $0x3,%r12d
jl     11c4 <facname_to_factor+0x74>
lea    -0x2(%r12),%ebp
cmpb   $0x3a,0x0(%r13,%rbp,1)
jne    11c4 <facname_to_factor+0x74>
lea    -0x1(%r12),%eax
cmpb   $0x31,0x0(%r13,%rax,1)
je     11a8 <facname_to_factor+0x58>
lea    0x1(%r15),%esi
lea    0xea2(%rip),%rdi
mov    %r14d,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1030 <my_errorf@plt>
movb   $0x0,0x0(%r13,%rbp,1)
jmp    11c4 <facname_to_factor+0x74>
lea    0xe49(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <my_errorf@plt>
mov    %r13,%rdi
call   1050 <is_a_number@plt>
test   %eax,%eax
jne    11e8 <facname_to_factor+0x98>
lea    0x1(%r15),%esi
lea    0xe9c(%rip),%rdi
mov    %r14d,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1030 <my_errorf@plt>
mov    %r13,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    120d <facname_to_factor+0xbd>
lea    0x1(%r15),%esi
lea    0xef9(%rip),%rdi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <my_errorf@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    %r12d,%eax
je     124e <facname_to_factor+0xfe>
mov    %r13,%rdi
call   1040 <strlen@plt>
movslq %r12d,%rbx
add    $0xfffffffffffffffe,%rbx
cmp    %ebx,%eax
je     1248 <facname_to_factor+0xf8>
add    $0x1,%r15d
lea    0xefb(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1030 <my_errorf@plt>
movb   $0x3a,0x0(%r13,%rbx,1)
mov    %ebp,%edi
not    %edi
shr    $0x1f,%edi
call   1070 <my_assert_always@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [61 x i8] c"facname_to_factor: empty facname on line %d pos %d, but how?\00"
@.str.1 = [58 x i8] c"factor %d on line %d (%s) has : but is not followed by 1.\00"
@.str.2 = [131 x i8] c"factors should all be of the form <number> or <number>:1 but\0A factor number %d on line %d has the following before the \22:1\22:\0A\22%s\22\0A\00"
@.str.3 = [57 x i8] c"factor number %d on line %d has value %d which is crazy\0A\00"
@.str.4 = [83 x i8] c"facname_to_factor: internal error: len craziness on factor %d, line %d, facname %s\00"
define i32 @facname_to_factor(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
store i32 -77, i32* %8
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
br label %17
17: ; preds = %13, %3
%18 = load i32, i32* %7
%19 = icmp sgt i32 %18, 2
br i1 %19, label %20, label %50
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = load i32, i32* %7
%23 = sub nsw i32 %22, 2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 58
br i1 %28, label %29, label %50
29: ; preds = %20
%30 = load i8*, i8** %4
%31 = load i32, i32* %7
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 49
br i1 %37, label %38, label %44
38: ; preds = %29
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %5
%42 = load i8*, i8** %4
%43 = call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %41, i8* %42)
br label %44
44: ; preds = %38, %29
%45 = load i8*, i8** %4
%46 = load i32, i32* %7
%47 = sub nsw i32 %46, 2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
store i8 0, i8* %49
br label %50
50: ; preds = %44, %20, %17
%51 = load i8*, i8** %4
%52 = call i32 @is_a_number(i8* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %50
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
%57 = load i32, i32* %5
%58 = load i8*, i8** %4
%59 = call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 %56, i32 %57, i8* %58)
br label %60
60: ; preds = %54, %50
%61 = load i8*, i8** %4
%62 = call i32 @atoi(i8* %61)
store i32 %62, i32* %8
%63 = load i32, i32* %8
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %60
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
%68 = load i32, i32* %5
%69 = load i32, i32* %8
%70 = call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 %67, i32 %68, i32 %69)
br label %71
71: ; preds = %65, %60
%72 = load i8*, i8** %4
%73 = call i32 @strlen(i8* %72)
%74 = load i32, i32* %7
%75 = icmp ne i32 %73, %74
br i1 %75, label %76, label %94
76: ; preds = %71
%77 = load i8*, i8** %4
%78 = call i32 @strlen(i8* %77)
%79 = load i32, i32* %7
%80 = sub nsw i32 %79, 2
%81 = icmp ne i32 %78, %80
br i1 %81, label %82, label %88
82: ; preds = %76
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
%85 = load i32, i32* %5
%86 = load i8*, i8** %4
%87 = call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.4, i64 0, i64 0), i32 %84, i32 %85, i8* %86)
br label %88
88: ; preds = %82, %76
%89 = load i8*, i8** %4
%90 = load i32, i32* %7
%91 = sub nsw i32 %90, 2
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %89, i64 %92
store i8 58, i8* %93
br label %94
94: ; preds = %88, %71
%95 = load i32, i32* %8
%96 = icmp sge i32 %95, 0
%97 = zext i1 %96 to i32
%98 = call i32 @my_assert_always(i32 %97)
%99 = load i32, i32* %8
ret i32 %99
}

LLVM IR (-O2):
@.str = [61 x i8] c"facname_to_factor: empty facname on line %d pos %d, but how?\00"
@.str.1 = [58 x i8] c"factor %d on line %d (%s) has : but is not followed by 1.\00"
@.str.2 = [131 x i8] c"factors should all be of the form <number> or <number>:1 but\0A factor number %d on line %d has the following before the \22:1\22:\0A\22%s\22\0A\00"
@.str.3 = [57 x i8] c"factor number %d on line %d has value %d which is crazy\0A\00"
@.str.4 = [83 x i8] c"facname_to_factor: internal error: len craziness on factor %d, line %d, facname %s\00"
define i32 @facname_to_factor(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
br label %26
8: ; preds = %3
%9 = icmp sgt i32 %4, 2
br i1 %9, label %10, label %26
10: ; preds = %8
%11 = add nsw i32 %4, -2
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 58
br i1 %15, label %16, label %26
16: ; preds = %10
%17 = add nsw i32 %4, -1
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 49
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = add nsw i32 %2, 1
%24 = tail call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %1, i8* %0)
br label %25
25: ; preds = %22, %16
store i8 0, i8* %13
br label %26
26: ; preds = %6, %25, %10, %8
%27 = tail call i32 @is_a_number(i8* %0)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = add nsw i32 %2, 1
%31 = tail call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %1, i8* %0)
br label %32
32: ; preds = %29, %26
%33 = tail call i32 @atoi(i8* %0)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = add nsw i32 %2, 1
%37 = tail call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %1, i32 %33)
br label %38
38: ; preds = %35, %32
%39 = tail call i32 @strlen(i8* %0)
%40 = icmp eq i32 %39, %4
br i1 %40, label %51, label %41
41: ; preds = %38
%42 = tail call i32 @strlen(i8* %0)
%43 = add nsw i32 %4, -2
%44 = icmp eq i32 %42, %43
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = add nsw i32 %2, 1
%47 = tail call i32 (i8*, i32, i32, ...) @my_errorf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %1, i8* %0)
br label %48
48: ; preds = %45, %41
%49 = sext i32 %43 to i64
%50 = getelementptr inbounds i8, i8* %0, i64 %49
store i8 58, i8* %50
br label %51
51: ; preds = %48, %38
%52 = xor i32 %33, -1
%53 = lshr i32 %52, 31
%54 = tail call i32 @my_assert_always(i32 %53)
ret i32 %33
}