#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 strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int);
const char *try_option(const char *p, const char *q, const char *opt) {
  int len;
  len = strlen(opt);
  return (q - p > len && strncmp(p, opt, len) == 0) ? p + len : NULL;
}


x86 assembly (clang, -O0):
<try_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
jle    1186 <try_option+0x66>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1186 <try_option+0x66>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1191 <try_option+0x71>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    1191 <try_option+0x71>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try_option>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rdx,%rdi
call   1040 <strlen@plt>
sub    %r12,%rbx
movslq %eax,%r15
cmp    %r15,%rbx
jle    1163 <try_option+0x43>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
add    %r15,%r12
xor    %eax,%eax
test   %rcx,%rcx
cmove  %r12,%rax
jmp    1165 <try_option+0x45>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @try_option(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = ptrtoint i8* %1 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = sext i32 %4 to i64
%9 = icmp sgt i64 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = tail call i64 @strncmp(i8* %0, i8* %2, i32 %4)
%12 = icmp eq i64 %11, 0
%13 = getelementptr inbounds i8, i8* %0, i64 %8
%14 = select i1 %12, i8* %13, i8* null
br label %15
15: ; preds = %10, %3
%16 = phi i8* [ null, %3 ], [ %14, %10 ]
ret i8* %16
}