#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 find_instrument(char *);
int /*<<< orphan*/ process_line(char *, int, int, int, int *);
char *strchr(char *, char);
scalar_t__ strlen(char *);
void process_tab(char *buffer[], int nlines, int *nmeasures) {
  int i, j;
  char *sepr;
  int current_measure = 0;
  int new_staff_iminent = 1;
  int current_staff = -1;
  int last_measure_of_staff = -1;
  int in = -1;
  char *vbar;
  sepr = "|";
  for (i = 0; i < nlines; i++) {
    for (j = 0; j < (int)strlen(sepr); j++) {
      vbar = strchr(buffer[i], sepr[j]);
      if (vbar != NULL)
        break;
    }
    if (vbar == NULL) {
      new_staff_iminent = 1;
      continue;
    }
    if (new_staff_iminent) {
      new_staff_iminent = 0;
      current_staff++;
      current_measure = last_measure_of_staff + 1;
    }
    in = find_instrument(buffer[i]);
    process_line(vbar, in, current_measure, current_staff,
                 &last_measure_of_staff);
  }
  *nmeasures = last_measure_of_staff + 1;
}


x86 assembly (clang, -O0):
<process_tab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movl   $0xffffffff,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126e <process_tab+0x12e>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jge    11fc <process_tab+0xbc>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     11e9 <process_tab+0xa9>
jmp    11fc <process_tab+0xbc>
jmp    11ee <process_tab+0xae>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119b <process_tab+0x5b>
cmpq   $0x0,-0x48(%rbp)
jne    1213 <process_tab+0xd3>
movl   $0x1,-0x30(%rbp)
jmp    1260 <process_tab+0x120>
cmpl   $0x0,-0x30(%rbp)
je     1236 <process_tab+0xf6>
movl   $0x0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <find_instrument@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x34(%rbp),%ecx
lea    -0x38(%rbp),%r8
call   1060 <process_line@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <process_tab+0x48>
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_tab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x20(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
test   %esi,%esi
jle    11f3 <process_tab+0xc3>
mov    %rdx,0x10(%rsp)
mov    %esi,%eax
mov    %rax,0x18(%rsp)
xor    %r12d,%r12d
mov    $0x1,%r15d
mov    $0xffffffff,%r13d
xor    %ebx,%ebx
jmp    11c2 <process_tab+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%r14
mov    0xc(%rsp),%eax
add    $0x1,%eax
xor    %ecx,%ecx
test   %r15d,%r15d
setne  %cl
cmovne %eax,%ebx
add    %ecx,%r13d
mov    %rbp,%rdi
call   1040 <find_instrument@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
lea    0xc(%rsp),%r8
call   1050 <process_line@plt>
xor    %r15d,%r15d
add    $0x1,%r12
cmp    %r12,0x18(%rsp)
je     11e5 <process_tab+0xb5>
mov    0x20(%rsp),%rax
mov    (%rax,%r12,8),%rbp
mov    %rbp,%rdi
mov    $0x7c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1180 <process_tab+0x50>
mov    $0x1,%r15d
jmp    11b7 <process_tab+0x87>
mov    0xc(%rsp),%eax
add    $0x1,%eax
mov    0x10(%rsp),%rdx
jmp    11f5 <process_tab+0xc5>
xor    %eax,%eax
mov    %eax,(%rdx)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"|\00"
define void @process_tab(i8** %0, i32 %1, i32* %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %10
store i32 1, i32* %11
store i32 -1, i32* %12
store i32 -1, i32* %13
store i32 -1, i32* %14
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9
store i32 0, i32* %7
br label %16
16: ; preds = %70, %3
%17 = load i32, i32* %7
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %73
20: ; preds = %16
store i32 0, i32* %8
br label %21
21: ; preds = %43, %20
%22 = load i32, i32* %8
%23 = load i8*, i8** %9
%24 = call i64 @strlen(i8* %23)
%25 = trunc i64 %24 to i32
%26 = icmp slt i32 %22, %25
br i1 %26, label %27, label %46
27: ; preds = %21
%28 = load i8**, i8*** %4
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = load i8*, i8** %9
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = call i8* @strchr(i8* %32, i8 signext %37)
store i8* %38, i8** %15
%39 = load i8*, i8** %15
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %42
41: ; preds = %27
br label %46
42: ; preds = %27
br label %43
43: ; preds = %42
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %21
46: ; preds = %41, %21
%47 = load i8*, i8** %15
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %50
49: ; preds = %46
store i32 1, i32* %11
br label %70
50: ; preds = %46
%51 = load i32, i32* %11
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %50
store i32 0, i32* %11
%54 = load i32, i32* %12
%55 = add nsw i32 %54, 1
store i32 %55, i32* %12
%56 = load i32, i32* %13
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
br label %58
58: ; preds = %53, %50
%59 = load i8**, i8*** %4
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 @find_instrument(i8* %63)
store i32 %64, i32* %14
%65 = load i8*, i8** %15
%66 = load i32, i32* %14
%67 = load i32, i32* %10
%68 = load i32, i32* %12
%69 = call i32 @process_line(i8* %65, i32 %66, i32 %67, i32 %68, i32* %13)
br label %70
70: ; preds = %58, %49
%71 = load i32, i32* %7
%72 = add nsw i32 %71, 1
store i32 %72, i32* %7
br label %16
73: ; preds = %16
%74 = load i32, i32* %13
%75 = add nsw i32 %74, 1
%76 = load i32*, i32** %6
store i32 %75, i32* %76
ret void
}

LLVM IR (-O2):
define void @process_tab(i8** nocapture %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %37
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %28
%10 = phi i64 [ 0, %7 ], [ %32, %28 ]
%11 = phi i32 [ -1, %7 ], [ %31, %28 ]
%12 = phi i32 [ 1, %7 ], [ %30, %28 ]
%13 = phi i32 [ 0, %7 ], [ %29, %28 ]
%14 = getelementptr inbounds i8*, i8** %0, i64 %10
%15 = load i8*, i8** %14
%16 = call i8* @strchr(i8* dereferenceable(1) %15, i8 signext 124)
%17 = icmp eq i8* %16, null
br i1 %17, label %28, label %18
18: ; preds = %9
%19 = icmp eq i32 %12, 0
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
%22 = select i1 %19, i32 %13, i32 %21
%23 = xor i1 %19, true
%24 = zext i1 %23 to i32
%25 = add nsw i32 %11, %24
%26 = call i32 @find_instrument(i8* %15)
%27 = call i32 @process_line(i8* %16, i32 %26, i32 %22, i32 %25, i32* %4)
br label %28
28: ; preds = %9, %18
%29 = phi i32 [ %22, %18 ], [ %13, %9 ]
%30 = phi i32 [ 0, %18 ], [ 1, %9 ]
%31 = phi i32 [ %25, %18 ], [ %11, %9 ]
%32 = add nuw nsw i64 %10, 1
%33 = icmp eq i64 %32, %8
br i1 %33, label %34, label %9
34: ; preds = %28
%35 = load i32, i32* %4
%36 = add i32 %35, 1
br label %37
37: ; preds = %34, %3
%38 = phi i32 [ %36, %34 ], [ 0, %3 ]
store i32 %38, i32* %2
ret void
}