#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 */
char *NextAmpersand(char *);
int /*<<< orphan*/ diagnostics(int, char *, int, int);
int HA_CountColumnsInHAlign(char **lines, int n) {
  int i, max_col = 0;
  for (i = 0; i < n; i++) {
    int col = 1;
    char *s = lines[i];
    while ((s = NextAmpersand(s)) && *s != '\0') {
      col++;
      s++;
    }
    diagnostics(5, "line[%d] has %d columns", i, col);
    if (col > max_col)
      max_col = col;
  }
  return max_col;
}


x86 assembly (clang, -O0):
<HA_CountColumnsInHAlign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f5 <HA_CountColumnsInHAlign+0xd5>
movl   $0x1,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <NextAmpersand@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     118f <HA_CountColumnsInHAlign+0x6f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    119f <HA_CountColumnsInHAlign+0x7f>
jmp    11b9 <HA_CountColumnsInHAlign+0x99>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1160 <HA_CountColumnsInHAlign+0x40>
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    $0x5,%edi
lea    0xe35(%rip),%rsi
call   1030 <diagnostics@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11e2 <HA_CountColumnsInHAlign+0xc2>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <HA_CountColumnsInHAlign+0xc7>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <HA_CountColumnsInHAlign+0x1d>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HA_CountColumnsInHAlign>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11ab <HA_CountColumnsInHAlign+0x8b>
mov    %rdi,%r14
mov    %esi,%r13d
xor    %ebx,%ebx
lea    0xec2(%rip),%r15
xor    %r12d,%r12d
jmp    1171 <HA_CountColumnsInHAlign+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x5,%edi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1030 <diagnostics@plt>
cmp    %r12d,%ebp
cmovg  %ebp,%r12d
add    $0x1,%rbx
cmp    %r13,%rbx
je     11ae <HA_CountColumnsInHAlign+0x8e>
mov    (%r14,%rbx,8),%rdi
call   1040 <NextAmpersand@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1150 <HA_CountColumnsInHAlign+0x30>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x0,(%rax)
je     1150 <HA_CountColumnsInHAlign+0x30>
add    $0x1,%ebp
add    $0x1,%rax
mov    %rax,%rdi
call   1040 <NextAmpersand@plt>
test   %rax,%rax
jne    1190 <HA_CountColumnsInHAlign+0x70>
jmp    1150 <HA_CountColumnsInHAlign+0x30>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"line[%d] has %d columns\00"
define i32 @HA_CountColumnsInHAlign(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %9
9: ; preds = %45, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %48
13: ; preds = %9
store i32 1, i32* %7
%14 = load i8**, i8*** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
store i8* %18, i8** %8
br label %19
19: ; preds = %30, %13
%20 = load i8*, i8** %8
%21 = call i8* @NextAmpersand(i8* %20)
store i8* %21, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i8*, i8** %8
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br label %28
28: ; preds = %23, %19
%29 = phi i1 [ false, %19 ], [ %27, %23 ]
br i1 %29, label %30, label %35
30: ; preds = %28
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %8
br label %19
35: ; preds = %28
%36 = load i32, i32* %5
%37 = load i32, i32* %7
%38 = call i32 @diagnostics(i32 5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %37)
%39 = load i32, i32* %7
%40 = load i32, i32* %6
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = load i32, i32* %7
store i32 %43, i32* %6
br label %44
44: ; preds = %42, %35
br label %45
45: ; preds = %44
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %9
48: ; preds = %9
%49 = load i32, i32* %6
ret i32 %49
}

LLVM IR (-O2):
@.str = [24 x i8] c"line[%d] has %d columns\00"
define i32 @HA_CountColumnsInHAlign(i8** nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %31
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %23
%7 = phi i64 [ 0, %4 ], [ %29, %23 ]
%8 = phi i32 [ 0, %4 ], [ %28, %23 ]
%9 = getelementptr inbounds i8*, i8** %0, i64 %7
%10 = load i8*, i8** %9
%11 = tail call i8* @NextAmpersand(i8* %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %13
13: ; preds = %6, %18
%14 = phi i8* [ %21, %18 ], [ %11, %6 ]
%15 = phi i32 [ %19, %18 ], [ 1, %6 ]
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = add nuw nsw i32 %15, 1
%20 = getelementptr inbounds i8, i8* %14, i64 1
%21 = tail call i8* @NextAmpersand(i8* %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %13
23: ; preds = %13, %18, %6
%24 = phi i32 [ 1, %6 ], [ %19, %18 ], [ %15, %13 ]
%25 = trunc i64 %7 to i32
%26 = tail call i32 @diagnostics(i32 5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %24)
%27 = icmp sgt i32 %24, %8
%28 = select i1 %27, i32 %24, i32 %8
%29 = add nuw nsw i64 %7, 1
%30 = icmp eq i64 %29, %5
br i1 %30, label %31, label %6
31: ; preds = %23, %2
%32 = phi i32 [ 0, %2 ], [ %28, %23 ]
ret i32 %32
}