#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 dlg_count_wchars(char const *);
int *dlg_index_columns(char const *);
int dlg_limit_columns(const char *string, int limit, int offset) {
  const int *cols = dlg_index_columns(string);
  int result = dlg_count_wchars(string);
  while (result > 0 && (cols[result] - cols[offset]) > limit)
    --result;
  return result;
}


x86 assembly (clang, -O0):
<dlg_limit_columns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <dlg_index_columns@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <dlg_count_wchars@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jle    1179 <dlg_limit_columns+0x59>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%rcx
movslq -0x10(%rbp),%rdx
sub    (%rcx,%rdx,4),%eax
cmp    -0xc(%rbp),%eax
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1189 <dlg_limit_columns+0x69>
jmp    1197 <dlg_limit_columns+0x77>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <dlg_limit_columns+0x2b>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dlg_limit_columns>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
call   1030 <dlg_index_columns@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <dlg_count_wchars@plt>
test   %eax,%eax
jle    1167 <dlg_limit_columns+0x47>
movslq %r14d,%rcx
mov    (%rbx,%rcx,4),%ecx
nopl   0x0(%rax)
mov    %eax,%edx
mov    (%rbx,%rdx,4),%edx
sub    %ecx,%edx
cmp    %ebp,%edx
jle    1167 <dlg_limit_columns+0x47>
lea    -0x1(%rax),%edx
cmp    $0x1,%eax
mov    %edx,%eax
jg     1150 <dlg_limit_columns+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dlg_limit_columns(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32* @dlg_index_columns(i8* %9)
store i32* %10, i32** %7
%11 = load i8*, i8** %4
%12 = call i32 @dlg_count_wchars(i8* %11)
store i32 %12, i32* %8
br label %13
13: ; preds = %32, %3
%14 = load i32, i32* %8
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load i32*, i32** %7
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = load i32*, i32** %7
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = sub nsw i32 %21, %26
%28 = load i32, i32* %5
%29 = icmp sgt i32 %27, %28
br label %30
30: ; preds = %16, %13
%31 = phi i1 [ false, %13 ], [ %29, %16 ]
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = load i32, i32* %8
%34 = add nsw i32 %33, -1
store i32 %34, i32* %8
br label %13
35: ; preds = %30
%36 = load i32, i32* %8
ret i32 %36
}

LLVM IR (-O2):
define i32 @dlg_limit_columns(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32* @dlg_index_columns(i8* %0)
%5 = tail call i32 @dlg_count_wchars(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %3
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i32, i32* %4, i64 %8
%10 = load i32, i32* %9
br label %11
11: ; preds = %7, %18
%12 = phi i32 [ %5, %7 ], [ %19, %18 ]
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %4, i64 %13
%15 = load i32, i32* %14
%16 = sub nsw i32 %15, %10
%17 = icmp sgt i32 %16, %1
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = add nsw i32 %12, -1
%20 = icmp sgt i32 %12, 1
br i1 %20, label %11, label %21
21: ; preds = %11, %18, %3
%22 = phi i32 [ %5, %3 ], [ 0, %18 ], [ %12, %11 ]
ret i32 %22
}