#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__ memcmp(char *, char const *, size_t);
size_t strlen(char const *);
int str_begins_with2(char *str, const char *pref1, const char *pref2) {
  size_t len1 = strlen(pref1);
  return (memcmp(str, pref1, len1) == 0) &&
         (memcmp(str + len1, pref2, strlen(pref2)) == 0);
}


x86 assembly (clang, -O0):
<str_begins_with2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    119b <str_begins_with2+0x7b>
mov    -0x8(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_begins_with2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1178 <str_begins_with2+0x58>
add    %r15,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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