#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 */
typedef scalar_t__ memcmp;

/* Variables and functions */
size_t strnlen(char const *, size_t);
char *(strnstarts)(const char *string, const char *desired, size_t maxlen) {
  size_t n = strnlen(string, maxlen);
  size_t m = strnlen(desired, maxlen);
  if (n < m)
    return NULL;
  return (memcmp)(string, desired, m) ? NULL : string;
}


x86 assembly (clang, -O0):
<strnstarts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strnlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strnlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1161 <strnstarts+0x51>
movq   $0x0,-0x8(%rbp)
jmp    1187 <strnstarts+0x77>
cmpq   $0x0,-0x30(%rbp)
je     1177 <strnstarts+0x67>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    117f <strnstarts+0x6f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strnstarts>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,%rsi
call   1030 <strnlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strnlen@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmovne %rcx,%rbx
cmp    %rax,%r12
cmovb  %rcx,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strnstarts(i8* %0, i8* nocapture %1, i64 %2) {
%4 = tail call i64 @strnlen(i8* %0, i64 %2)
%5 = tail call i64 @strnlen(i8* %1, i64 %2)
%6 = icmp ult i64 %4, %5
%7 = icmp eq i64 %5, 0
%8 = select i1 %7, i8* %0, i8* null
%9 = select i1 %6, i8* null, i8* %8
ret i8* %9
}