#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 *malloc(int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int str_match(char *bufcpy) {
  char *mot3 = "";
  int nbsp = 0;
  int i = 0;
  while (bufcpy[i] != '\n') {
    if (nbsp == 2) {
      char *tmp = malloc(strlen(mot3) + 2);
      strcpy(tmp, mot3);
      tmp[strlen(mot3)] = bufcpy[i];
      tmp[strlen(mot3) + 1] = '\0';
      mot3 = tmp;
    }
    if (bufcpy[i] == ' ') {
      nbsp++;
    }
    i++;
  }
  if (strcmp(mot3, "HTTP/1.1") == 0 || strcmp(mot3, "HTTP/1.0") == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<str_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     122b <str_match+0xeb>
cmpl   $0x2,-0x1c(%rbp)
jne    11ff <str_match+0xbf>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x39(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x39(%rbp),%dl
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    121d <str_match+0xdd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1165 <str_match+0x25>
mov    -0x18(%rbp),%rdi
lea    0xdca(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     125f <str_match+0x11f>
mov    -0x18(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    126b <str_match+0x12b>
movl   $0x1,-0x4(%rbp)
jmp    1272 <str_match+0x132>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_match>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rdi),%al
cmp    $0xa,%al
jne    118c <str_match+0x4c>
lea    0xebc(%rip),%r14
lea    0xea4(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1202 <str_match+0xc2>
lea    0xe95(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    1207 <str_match+0xc7>
mov    %rdi,%rbx
lea    0xe7b(%rip),%r14
xor    %ebp,%ebp
jmp    11b5 <str_match+0x75>
nopw   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0x20,%al
sete   %cl
add    %ecx,%ebp
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0xa,%al
je     1155 <str_match+0x15>
cmp    $0x2,%ebp
jne    11a0 <str_match+0x60>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
movzbl (%rbx),%r12d
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
mov    %r12b,(%r15,%rax,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,0x1(%rax,%r15,1)
movzbl (%rbx),%eax
mov    %r15,%r14
jmp    11a0 <str_match+0x60>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [9 x i8] c"HTTP/1.1\00"
@.str.2 = [9 x i8] c"HTTP/1.0\00"
define i32 @str_match(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %55, %1
%9 = load i8*, i8** %3
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %58
16: ; preds = %8
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %44
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 2
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = load i8*, i8** %4
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i8*, i8** %3
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %7
%33 = load i8*, i8** %4
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 %31, i8* %36
%37 = load i8*, i8** %7
%38 = load i8*, i8** %4
%39 = call i32 @strlen(i8* %38)
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %37, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %7
store i8* %43, i8** %4
br label %44
44: ; preds = %19, %16
%45 = load i8*, i8** %3
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 32
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %55
55: ; preds = %52, %44
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %8
58: ; preds = %8
%59 = load i8*, i8** %4
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %66, label %62
62: ; preds = %58
%63 = load i8*, i8** %4
%64 = call i64 @strcmp(i8* %63, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %62, %58
store i32 1, i32* %2
br label %68
67: ; preds = %62
store i32 0, i32* %2
br label %68
68: ; preds = %67, %66
%69 = load i32, i32* %2
ret i32 %69
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [9 x i8] c"HTTP/1.1\00"
@.str.2 = [9 x i8] c"HTTP/1.0\00"
define i32 @str_match(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 10
br i1 %3, label %35, label %4
4: ; preds = %1, %25
%5 = phi i8 [ %33, %25 ], [ %2, %1 ]
%6 = phi i64 [ %31, %25 ], [ 0, %1 ]
%7 = phi i8* [ %32, %25 ], [ %0, %1 ]
%8 = phi i32 [ %30, %25 ], [ 0, %1 ]
%9 = phi i8* [ %27, %25 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ]
%10 = icmp eq i32 %8, 2
br i1 %10, label %11, label %25
11: ; preds = %4
%12 = tail call i32 @strlen(i8* %9)
%13 = add nsw i32 %12, 2
%14 = tail call i8* @malloc(i32 %13)
%15 = tail call i32 @strcpy(i8* %14, i8* %9)
%16 = load i8, i8* %7
%17 = tail call i32 @strlen(i8* %9)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
store i8 %16, i8* %19
%20 = tail call i32 @strlen(i8* %9)
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %14, i64 %22
store i8 0, i8* %23
%24 = load i8, i8* %7
br label %25
25: ; preds = %11, %4
%26 = phi i8 [ %24, %11 ], [ %5, %4 ]
%27 = phi i8* [ %14, %11 ], [ %9, %4 ]
%28 = icmp eq i8 %26, 32
%29 = zext i1 %28 to i32
%30 = add nuw nsw i32 %8, %29
%31 = add nuw i64 %6, 1
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 10
br i1 %34, label %35, label %4
35: ; preds = %25, %1
%36 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ], [ %27, %25 ]
%37 = tail call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = tail call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
%42 = zext i1 %41 to i32
br label %43
43: ; preds = %39, %35
%44 = phi i32 [ 1, %35 ], [ %42, %39 ]
ret i32 %44
}