#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 */
scalar_t__ isspace(char const);
int strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int);
const char *startswith(const char *string, const char *pattern) {
  int l = strlen(pattern);
  if (strlen(string) <= l)
    return NULL;
  if (strncmp(string, pattern, l) != 0)
    return NULL;
  string += l;
  if (!isspace(*string))
    return NULL;
  while (isspace(*string))
    string++;
  return string;
}


x86 assembly (clang, -O0):
<startswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x1c(%rbp),%eax
jg     116b <startswith+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11fa <startswith+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1192 <startswith+0x62>
movq   $0x0,-0x8(%rbp)
jmp    11fa <startswith+0xca>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
jne    11c6 <startswith+0x96>
movq   $0x0,-0x8(%rbp)
jmp    11fa <startswith+0xca>
jmp    11cb <startswith+0x9b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11f2 <startswith+0xc2>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11cb <startswith+0x9b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startswith>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jle    1162 <startswith+0x32>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     116c <startswith+0x3c>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
movslq %ebp,%rbx
movsbl (%r14,%rbx,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     1162 <startswith+0x32>
add    %r14,%rbx
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1050 <isspace@plt>
test   %rax,%rax
jne    1190 <startswith+0x60>
jmp    1164 <startswith+0x34>

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

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