#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 *rindex(char *, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int find_line_length(char *txt, char delim, int len) {
  char buf[200];
  char *cont;
  int i = 0;
  if (!txt)
    return 0;
  if (strlen(txt) < len)
    return strlen(txt);
  strncpy(buf, txt, len);
  cont = rindex(buf, (int)delim);
  i = ((int)cont - (int)buf);
  i++;
  return i;
}


x86 assembly (clang, -O0):
<find_line_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0xec(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1169 <find_line_length+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <find_line_length+0xb4>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x18(%rbp),%eax
jge    118c <find_line_length+0x5c>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    11e4 <find_line_length+0xb4>
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0xe0(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1050 <rindex@plt>
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rax
lea    -0xe0(%rbp),%rcx
sub    %ecx,%eax
mov    %eax,-0xec(%rbp)
mov    -0xec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xec(%rbp)
mov    -0xec(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_line_length>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xc8,%rsp
test   %rdi,%rdi
je     1168 <find_line_length+0x38>
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    %ebp,%eax
jge    116c <find_line_length+0x3c>
mov    %rbx,%rdi
add    $0xc8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strlen@plt>
xor    %eax,%eax
jmp    118e <find_line_length+0x5e>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movsbl %r14b,%esi
mov    %r15,%rdi
call   1050 <rindex@plt>
sub    %r15d,%eax
add    $0x1,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_line_length(i8* %0, i8 signext %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca [200 x i8]
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i8 %1, i8* %6
store i32 %2, i32* %7
store i32 0, i32* %10
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %3
store i32 0, i32* %4
br label %39
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %4
br label %39
22: ; preds = %14
%23 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%24 = load i8*, i8** %5
%25 = load i32, i32* %7
%26 = call i32 @strncpy(i8* %23, i8* %24, i32 %25)
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
%30 = call i8* @rindex(i8* %27, i32 %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = ptrtoint i8* %31 to i32
%33 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%34 = ptrtoint i8* %33 to i32
%35 = sub nsw i32 %32, %34
store i32 %35, i32* %10
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
%38 = load i32, i32* %10
store i32 %38, i32* %4
br label %39
39: ; preds = %22, %19, %13
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @find_line_length(i8* %0, i8 signext %1, i32 %2) {
%4 = alloca [200 x i8]
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %22, label %7
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp slt i32 %8, %2
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %0)
br label %22
12: ; preds = %7
%13 = call i32 @strncpy(i8* %5, i8* %0, i32 %2)
%14 = sext i8 %1 to i32
%15 = call i8* @rindex(i8* %5, i32 %14)
%16 = ptrtoint i8* %15 to i64
%17 = trunc i64 %16 to i32
%18 = ptrtoint [200 x i8]* %4 to i64
%19 = trunc i64 %18 to i32
%20 = sub i32 1, %19
%21 = add i32 %20, %17
br label %22
22: ; preds = %3, %12, %10
%23 = phi i32 [ %11, %10 ], [ %21, %12 ], [ 0, %3 ]
ret i32 %23
}