#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 */
scalar_t__ clr_col(char const *, int const, int const, int);
int col_penalty(const char *Dots, const int Hgt, const int Wid) {
  int x, penalty = 0, penalty_local = 0;
  for (x = 1; x < Wid - 1; x++) {
    if (clr_col(Dots, Hgt, Wid, x)) {
      if (penalty_local == 0) {
        penalty_local = Hgt;
      } else {
        penalty_local *= Hgt;
      }
    } else {
      if (penalty_local) {
        penalty += penalty_local;
        penalty_local = 0;
      }
    }
  }
  return penalty + penalty_local;
}


x86 assembly (clang, -O0):
<col_penalty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ba <col_penalty+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <clr_col@plt>
cmp    $0x0,%rax
je     1188 <col_penalty+0x78>
cmpl   $0x0,-0x1c(%rbp)
jne    1179 <col_penalty+0x69>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1183 <col_penalty+0x73>
mov    -0xc(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11a7 <col_penalty+0x97>
cmpl   $0x0,-0x1c(%rbp)
je     11a2 <col_penalty+0x92>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    11a7 <col_penalty+0x97>
jmp    11ac <col_penalty+0x9c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <col_penalty+0x27>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<col_penalty>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
mov    %edx,0x4(%rsp)
cmp    $0x3,%edx
jl     1196 <col_penalty+0x86>
mov    %esi,%r12d
mov    %rdi,%r14
mov    $0x2,%r13d
sub    0x4(%rsp),%r13d
xor    %ebx,%ebx
xor    %r15d,%r15d
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12d,%esi
mov    0x4(%rsp),%edx
mov    %ebp,%ecx
call   1030 <clr_col@plt>
test   %ebx,%ebx
mov    %ebx,%ecx
mov    $0x1,%edx
cmove  %edx,%ebx
imul   %r12d,%ebx
test   %rax,%rax
mov    $0x0,%eax
cmovne %eax,%ecx
cmove  %eax,%ebx
add    %ecx,%r15d
lea    0x1(%r13,%rbp,1),%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    1150 <col_penalty+0x40>
add    %r15d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @col_penalty(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %9
store i32 1, i32* %7
br label %10
10: ; preds = %41, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 1
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %44
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = call i64 @clr_col(i8* %16, i32 %17, i32 %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %15
%23 = load i32, i32* %9
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i32, i32* %5
store i32 %26, i32* %9
br label %31
27: ; preds = %22
%28 = load i32, i32* %5
%29 = load i32, i32* %9
%30 = mul nsw i32 %29, %28
store i32 %30, i32* %9
br label %31
31: ; preds = %27, %25
br label %40
32: ; preds = %15
%33 = load i32, i32* %9
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* %9
%37 = load i32, i32* %8
%38 = add nsw i32 %37, %36
store i32 %38, i32* %8
store i32 0, i32* %9
br label %39
39: ; preds = %35, %32
br label %40
40: ; preds = %39, %31
br label %41
41: ; preds = %40
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %10
44: ; preds = %10
%45 = load i32, i32* %8
%46 = load i32, i32* %9
%47 = add nsw i32 %45, %46
ret i32 %47
}

LLVM IR (-O2):
define i32 @col_penalty(i8* %0, i32 %1, i32 %2) {
%4 = add i32 %2, -1
%5 = icmp sgt i32 %2, 2
br i1 %5, label %6, label %22
6: ; preds = %3, %6
%7 = phi i32 [ %17, %6 ], [ 0, %3 ]
%8 = phi i32 [ %16, %6 ], [ 0, %3 ]
%9 = phi i32 [ %18, %6 ], [ 1, %3 ]
%10 = tail call i64 @clr_col(i8* %0, i32 %1, i32 %2, i32 %9)
%11 = icmp eq i64 %10, 0
%12 = icmp eq i32 %7, 0
%13 = select i1 %12, i32 1, i32 %7
%14 = mul nsw i32 %13, %1
%15 = select i1 %11, i32 %7, i32 0
%16 = add nsw i32 %8, %15
%17 = select i1 %11, i32 0, i32 %14
%18 = add nuw nsw i32 %9, 1
%19 = icmp eq i32 %18, %4
br i1 %19, label %20, label %6
20: ; preds = %6
%21 = add nsw i32 %17, %16
br label %22
22: ; preds = %20, %3
%23 = phi i32 [ %21, %20 ], [ 0, %3 ]
ret i32 %23
}