#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 */
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char const *, char *);
int ureq_get_header(char *h, const char *r) {
  const char *p = strstr(r, "\r\n");
  if (!p)
    return 0;
  if ((p - r) < 14)
    return 0;
  strncpy(h, r, (p - r));
  return 1;
}


x86 assembly (clang, -O0):
<ureq_get_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115b <ureq_get_header+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    119d <ureq_get_header+0x7d>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
cmp    $0xe,%rax
jge    117c <ureq_get_header+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    119d <ureq_get_header+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ureq_get_header>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xecf(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
mov    %rax,%rdx
xor    %eax,%eax
test   %rdx,%rdx
je     115c <ureq_get_header+0x3c>
sub    %rbx,%rdx
cmp    $0xe,%rdx
jl     115c <ureq_get_header+0x3c>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
define i32 @ureq_get_header(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %30
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = load i8*, i8** %5
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
%18 = icmp slt i64 %17, 14
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 0, i32* %3
br label %30
20: ; preds = %12
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = load i8*, i8** %5
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = call i32 @strncpy(i8* %21, i8* %22, i32 %28)
store i32 1, i32* %3
br label %30
30: ; preds = %20, %19, %11
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
define i32 @ureq_get_header(i8* %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = ptrtoint i8* %3 to i64
%7 = ptrtoint i8* %1 to i64
%8 = sub i64 %6, %7
%9 = icmp slt i64 %8, 14
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = trunc i64 %8 to i32
%12 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %11)
br label %13
13: ; preds = %5, %2, %10
%14 = phi i32 [ 1, %10 ], [ 0, %2 ], [ 0, %5 ]
ret i32 %14
}