#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 *strdup(char const *);
unsigned int strlen(char const *);
scalar_t__ strncmp(char const *, char const *, unsigned int);
int startswithextractstring(const char *arg, const char *lookfor,
                            const char **ptrout) {
  const char *s = 0;
  unsigned prefixlen = strlen(lookfor);
  if (strncmp(arg, lookfor, prefixlen)) {
    return 0;
  }
  s = arg + prefixlen;
  *ptrout = strdup(s);
  return 1;
}


x86 assembly (clang, -O0):
<startswithextractstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     117e <startswithextractstring+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    11a6 <startswithextractstring+0x76>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startswithextractstring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1178 <startswithextractstring+0x48>
mov    %r15d,%eax
add    %rax,%rbx
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @startswithextractstring(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i8* null, i8** %8
%10 = load i8*, i8** %6
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %9
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = load i32, i32* %9
%15 = call i64 @strncmp(i8* %12, i8* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 0, i32* %4
br label %26
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = load i32, i32* %9
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = call i8* @strdup(i8* %23)
%25 = load i8**, i8*** %7
store i8* %24, i8** %25
store i32 1, i32* %4
br label %26
26: ; preds = %18, %17
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
define i32 @startswithextractstring(i8* %0, i8* %1, i8** nocapture writeonly %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i64 @strncmp(i8* %0, i8* %1, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = zext i32 %4 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i8* @strdup(i8* %9)
store i8* %10, i8** %2
br label %11
11: ; preds = %3, %7
%12 = phi i32 [ 1, %7 ], [ 0, %3 ]
ret i32 %12
}