#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 min_strips(int, int, char **);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, ...);
int main(void) {
  printf("Enter grid dimensions, followed by each element\n");
  printf("> ");
  int rows, cols;
  while (scanf("%d%d", &rows, &cols) == 2) {
    char grid[rows][cols];
    int i, j;
    for (i = 0; i < rows; i++) {
      for (j = 0; j < cols; j++) {
        scanf(" %c", &grid[i][j]);
      }
    }
    printf("Min strips = %d\n", min_strips(rows, cols, grid));
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x2,%eax
jne    1259 <main+0x129>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rsi
imul   %rax,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1220 <main+0xf0>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120d <main+0xdd>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rcx
movslq -0x2c(%rbp),%rax
imul   %rcx,%rax
add    %rax,%rsi
movslq -0x30(%rbp),%rax
add    %rax,%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11cb <main+0x9b>
jmp    1212 <main+0xe2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b8 <main+0x88>
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <min_strips@plt>
mov    %eax,%esi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    115b <main+0x2b>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x2,%eax
jne    1260 <main+0x120>
lea    0xe77(%rip),%rbx
jmp    11e6 <main+0xa6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x38(%rbp),%rdx
call   1050 <min_strips@plt>
lea    0xe5c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x40(%rbp),%rsp
lea    0xe31(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x2,%eax
jne    1260 <main+0x120>
mov    %rsp,%rcx
mov    -0x30(%rbp),%eax
mov    -0x2c(%rbp),%r13d
imul   %r13,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
test   %edi,%edi
mov    %rcx,-0x40(%rbp)
mov    %r15,-0x38(%rbp)
jle    11a0 <main+0x60>
xor    %r12d,%r12d
jmp    1233 <main+0xf3>
nopl   0x0(%rax)
add    $0x1,%r12
movslq %edi,%rax
add    %r13,%r15
cmp    %rax,%r12
jge    11a0 <main+0x60>
test   %esi,%esi
jle    1220 <main+0xe0>
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
lea    (%r15,%r14,1),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r14
movslq -0x2c(%rbp),%rsi
cmp    %rsi,%r14
jl     1240 <main+0x100>
mov    -0x30(%rbp),%edi
jmp    1220 <main+0xe0>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Enter grid dimensions, followed by each element\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [5 x i8] c"%d%d\00"
@.str.3 = [4 x i8] c" %c\00"
@.str.4 = [17 x i8] c"Min strips = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %47, %0
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %55
14: ; preds = %11
%15 = load i32, i32* %2
%16 = zext i32 %15 to i64
%17 = load i32, i32* %3
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %4
%20 = mul nuw i64 %16, %18
%21 = alloca i8, i64 %20
store i64 %16, i64* %5
store i64 %18, i64* %6
store i32 0, i32* %7
br label %22
22: ; preds = %44, %14
%23 = load i32, i32* %7
%24 = load i32, i32* %2
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %47
26: ; preds = %22
store i32 0, i32* %8
br label %27
27: ; preds = %40, %26
%28 = load i32, i32* %8
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = mul nsw i64 %33, %18
%35 = getelementptr inbounds i8, i8* %21, i64 %34
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %31
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %27
43: ; preds = %27
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %22
47: ; preds = %22
%48 = load i32, i32* %2
%49 = load i32, i32* %3
%50 = bitcast i8* %21 to i8**
%51 = call i32 @min_strips(i32 %48, i32 %49, i8** %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%54 = load i8*, i8** %4
br label %11
55: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [5 x i8] c"%d%d\00"
@.str.3 = [4 x i8] c" %c\00"
@.str.4 = [17 x i8] c"Min strips = %d\0A\00"
@str = [48 x i8] c"Enter grid dimensions, followed by each element\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2)
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %53
9: ; preds = %0, %44
%10 = load i32, i32* %1
%11 = zext i32 %10 to i64
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
%15 = mul nuw i64 %13, %11
%16 = alloca i8, i64 %15
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 0
%19 = load i32, i32* %2
br i1 %18, label %20, label %44
20: ; preds = %9, %38
%21 = phi i32 [ %39, %38 ], [ %17, %9 ]
%22 = phi i32 [ %40, %38 ], [ %19, %9 ]
%23 = phi i64 [ %41, %38 ], [ 0, %9 ]
%24 = icmp sgt i32 %22, 0
br i1 %24, label %25, label %38
25: ; preds = %20
%26 = mul nuw nsw i64 %23, %13
%27 = getelementptr inbounds i8, i8* %16, i64 %26
br label %28
28: ; preds = %25, %28
%29 = phi i64 [ 0, %25 ], [ %32, %28 ]
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = add nuw nsw i64 %29, 1
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %28, label %36
36: ; preds = %28
%37 = load i32, i32* %1
br label %38
38: ; preds = %36, %20
%39 = phi i32 [ %37, %36 ], [ %21, %20 ]
%40 = phi i32 [ %33, %36 ], [ %22, %20 ]
%41 = add nuw nsw i64 %23, 1
%42 = sext i32 %39 to i64
%43 = icmp slt i64 %41, %42
br i1 %43, label %20, label %44
44: ; preds = %38, %9
%45 = phi i32 [ %19, %9 ], [ %40, %38 ]
%46 = phi i32 [ %17, %9 ], [ %39, %38 ]
%47 = bitcast i8* %16 to i8**
%48 = call i32 @min_strips(i32 %46, i32 %45, i8** %47)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%51 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2)
%52 = icmp eq i32 %51, 2
br i1 %52, label %9, label %53
53: ; preds = %44, %0
ret i32 0
}