#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 EINVAL;
int /*<<< orphan*/ free(char *);
char *next_node(char **, int *);
scalar_t__ strncmp(char *, char *, int);
int count_common_nodes(char *to, char *from) {
  int err, common;
  char *to_node, *from_node;
  if (!to || !from)
    return -EINVAL;
  err = 0;
  common = 0;
  to_node = NULL;
  from_node = NULL;
  do {
    to_node = next_node(&to, &err);
    if (err || !to_node)
      break;
    from_node = next_node(&from, &err);
    if (err || !from_node)
      break;
    if (strncmp(to_node, from_node, 1000))
      break;
    ++to;
    ++from;
    ++common;
    do {
      free(to_node);
      to_node = NULL;
    } while (0);
    do {
      free(from_node);
      from_node = NULL;
    } while (0);
  } while (1);
  do {
    free(to_node);
    to_node = NULL;
  } while (0);
  do {
    free(from_node);
    from_node = NULL;
  } while (0);
  if (err)
    return err;
  return common;
}


x86 assembly (clang, -O0):
<count_common_nodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <count_common_nodes+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1169 <count_common_nodes+0x39>
xor    %eax,%eax
mov    0x2e81(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12a1 <count_common_nodes+0x171>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <next_node@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11ad <count_common_nodes+0x7d>
cmpq   $0x0,-0x28(%rbp)
jne    11b2 <count_common_nodes+0x82>
jmp    125a <count_common_nodes+0x12a>
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <next_node@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11d8 <count_common_nodes+0xa8>
cmpq   $0x0,-0x30(%rbp)
jne    11dd <count_common_nodes+0xad>
jmp    125a <count_common_nodes+0x12a>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x3e8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     11fe <count_common_nodes+0xce>
jmp    125a <count_common_nodes+0x12a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
jmp    1235 <count_common_nodes+0x105>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
jmp    124b <count_common_nodes+0x11b>
mov    $0x1,%al
test   $0x1,%al
jne    1187 <count_common_nodes+0x57>
jmp    125a <count_common_nodes+0x12a>
jmp    125f <count_common_nodes+0x12f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
jmp    1275 <count_common_nodes+0x145>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     129b <count_common_nodes+0x16b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a1 <count_common_nodes+0x171>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_common_nodes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x18(%rsp)
mov    %rsi,0x20(%rsp)
test   %rdi,%rdi
je     121b <count_common_nodes+0xeb>
test   %rsi,%rsi
je     121b <count_common_nodes+0xeb>
movl   $0x0,0xc(%rsp)
lea    0x18(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1050 <next_node@plt>
mov    %rax,%rbx
xor    %r14d,%r14d
cmpl   $0x0,0xc(%rsp)
jne    122a <count_common_nodes+0xfa>
test   %rbx,%rbx
je     122a <count_common_nodes+0xfa>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
lea    0x20(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0x18(%rsp),%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <next_node@plt>
mov    %rax,%r15
cmpl   $0x0,0xc(%rsp)
jne    1233 <count_common_nodes+0x103>
test   %r15,%r15
je     1233 <count_common_nodes+0x103>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3e8,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1233 <count_common_nodes+0x103>
addq   $0x1,0x18(%rsp)
addq   $0x1,0x20(%rsp)
add    $0x1,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <next_node@plt>
mov    %rax,%rbx
cmpl   $0x0,0xc(%rsp)
jne    1238 <count_common_nodes+0x108>
test   %rbx,%rbx
jne    11b0 <count_common_nodes+0x80>
jmp    1238 <count_common_nodes+0x108>
mov    0x2dbe(%rip),%rax
xor    %r14d,%r14d
sub    (%rax),%r14d
jmp    1254 <count_common_nodes+0x124>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
jmp    1238 <count_common_nodes+0x108>
mov    %r15,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
cmovne %eax,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
define i32 @count_common_nodes(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12, %2
%16 = load i32, i32* @EINVAL
%17 = sub nsw i32 0, %16
store i32 %17, i32* %3
br label %72
18: ; preds = %12
store i32 0, i32* %6
store i32 0, i32* %7
store i8* null, i8** %8
store i8* null, i8** %9
br label %19
19: ; preds = %56, %18
%20 = call i8* @next_node(i8** %4, i32* %6)
store i8* %20, i8** %8
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = load i8*, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %23, %19
br label %57
27: ; preds = %23
%28 = call i8* @next_node(i8** %5, i32* %6)
store i8* %28, i8** %9
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i8*, i8** %9
%33 = icmp ne i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %31, %27
br label %57
35: ; preds = %31
%36 = load i8*, i8** %8
%37 = load i8*, i8** %9
%38 = call i64 @strncmp(i8* %36, i8* %37, i32 1000)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
br label %57
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %5
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %48
48: ; preds = %41
%49 = load i8*, i8** %8
%50 = call i32 @free(i8* %49)
store i8* null, i8** %8
br label %51
51: ; preds = %48
br label %52
52: ; preds = %51
%53 = load i8*, i8** %9
%54 = call i32 @free(i8* %53)
store i8* null, i8** %9
br label %55
55: ; preds = %52
br label %56
56: ; preds = %55
br i1 true, label %19, label %57
57: ; preds = %56, %40, %34, %26
br label %58
58: ; preds = %57
%59 = load i8*, i8** %8
%60 = call i32 @free(i8* %59)
store i8* null, i8** %8
br label %61
61: ; preds = %58
br label %62
62: ; preds = %61
%63 = load i8*, i8** %9
%64 = call i32 @free(i8* %63)
store i8* null, i8** %9
br label %65
65: ; preds = %62
%66 = load i32, i32* %6
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = load i32, i32* %6
store i32 %69, i32* %3
br label %72
70: ; preds = %65
%71 = load i32, i32* %7
store i32 %71, i32* %3
br label %72
72: ; preds = %70, %68, %15
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@EINVAL = global i32 0
define i32 @count_common_nodes(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = bitcast i32* %5 to i8*
%7 = icmp ne i8* %0, null
%8 = icmp ne i8* %1, null
%9 = and i1 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @EINVAL
%12 = sub nsw i32 0, %11
br label %52
13: ; preds = %2
store i32 0, i32* %5
%14 = call i8* @next_node(i8** %3, i32* %5)
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
%17 = icmp ne i8* %14, null
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %43
19: ; preds = %13, %30
%20 = phi i8* [ %38, %30 ], [ %14, %13 ]
%21 = phi i32 [ %35, %30 ], [ 0, %13 ]
%22 = call i8* @next_node(i8** %4, i32* %5)
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 0
%25 = icmp ne i8* %22, null
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %27, label %43
27: ; preds = %19
%28 = call i64 @strncmp(i8* %20, i8* %22, i32 1000)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %43
30: ; preds = %27
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** %3
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %4
%35 = add nuw nsw i32 %21, 1
%36 = call i32 @free(i8* %20)
%37 = call i32 @free(i8* %22)
%38 = call i8* @next_node(i8** %3, i32* %5)
%39 = load i32, i32* %5
%40 = icmp eq i32 %39, 0
%41 = icmp ne i8* %38, null
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %19, label %43
43: ; preds = %27, %19, %30, %13
%44 = phi i32 [ 0, %13 ], [ %35, %30 ], [ %21, %19 ], [ %21, %27 ]
%45 = phi i8* [ %14, %13 ], [ %38, %30 ], [ %20, %19 ], [ %20, %27 ]
%46 = phi i8* [ null, %13 ], [ null, %30 ], [ %22, %19 ], [ %22, %27 ]
%47 = call i32 @free(i8* %45)
%48 = call i32 @free(i8* %46)
%49 = load i32, i32* %5
%50 = icmp eq i32 %49, 0
%51 = select i1 %50, i32 %44, i32 %49
br label %52
52: ; preds = %43, %10
%53 = phi i32 [ %12, %10 ], [ %51, %43 ]
ret i32 %53
}