#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*/ safestrcpy(char *, char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
const char *extract_reply(char *buf) {
  static char replybuf[80];
  int len;
  char *newline = strchr(buf, '\n');
  if (newline == NULL) {
    return NULL;
  }
  *newline++ = '\0';
  strcpy(replybuf, buf);
  len = strlen(replybuf);
  if (replybuf[len - 1] == '\r') {
    replybuf[len - 1] = 0;
    len--;
  }
  if (replybuf[len - 1] != '\n') {
    replybuf[len] = '\n';
    replybuf[len + 1] = '\0';
    len++;
  }
  safestrcpy(buf, newline, strlen(newline));
  return replybuf;
}


x86 assembly (clang, -O0):
<extract_reply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1176 <extract_reply+0x36>
movq   $0x0,-0x8(%rbp)
jmp    125d <extract_reply+0x11d>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
lea    0x2ebd(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2eb1(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e99(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    11e1 <extract_reply+0xa1>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e7c(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e5f(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     122a <extract_reply+0xea>
movslq -0x14(%rbp),%rcx
lea    0x2e47(%rip),%rax
movb   $0xa,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2e33(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1060 <safestrcpy@plt>
lea    0x2df7(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_reply>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c6 <extract_reply+0x86>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0x2eec(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdx
lea    -0x1(%rdx),%rcx
cmpb   $0xd,-0x1(%rdx,%r15,1)
jne    119b <extract_reply+0x5b>
mov    %ecx,%edx
lea    0x2ec1(%rip),%rsi
movb   $0x0,(%rcx,%rsi,1)
add    $0xfffffffe,%eax
movslq %eax,%rcx
mov    %edx,%eax
add    $0x1,%rbx
cmpb   $0xa,(%rcx,%r15,1)
je     11af <extract_reply+0x6f>
cltq
movw   $0xa,(%rax,%r15,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <safestrcpy@plt>
jmp    11c9 <extract_reply+0x89>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@extract_reply.replybuf = internal global [80 x i8] zeroinitializer
define i8* @extract_reply(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strchr(i8* %6, i8 signext 10)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %55
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
store i8 0, i8* %12
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 0), i8* %14)
%16 = call i32 @strlen(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 0))
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 13
br i1 %23, label %24, label %31
24: ; preds = %11
%25 = load i32, i32* %4
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 %27
store i8 0, i8* %28
%29 = load i32, i32* %4
%30 = add nsw i32 %29, -1
store i32 %30, i32* %4
br label %31
31: ; preds = %24, %11
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 10
br i1 %38, label %39, label %49
39: ; preds = %31
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 %41
store i8 10, i8* %42
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 %45
store i8 0, i8* %46
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %49
49: ; preds = %39, %31
%50 = load i8*, i8** %3
%51 = load i8*, i8** %5
%52 = load i8*, i8** %5
%53 = call i32 @strlen(i8* %52)
%54 = call i32 @safestrcpy(i8* %50, i8* %51, i32 %53)
store i8* getelementptr inbounds ([80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 0), i8** %2
br label %55
55: ; preds = %49, %10
%56 = load i8*, i8** %2
ret i8* %56
}

LLVM IR (-O2):
@extract_reply.replybuf = internal global [80 x i8] zeroinitializer
define i8* @extract_reply(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%3 = icmp eq i8* %2, null
br i1 %3, label %31, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
store i8 0, i8* %2
%6 = tail call i32 @strcpy(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 0), i8* %0)
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 0))
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 13
br i1 %12, label %13, label %16
13: ; preds = %4
store i8 0, i8* %10
%14 = add nsw i32 %7, -2
%15 = sext i32 %14 to i64
br label %16
16: ; preds = %13, %4
%17 = phi i64 [ %15, %13 ], [ %9, %4 ]
%18 = phi i32 [ %8, %13 ], [ %7, %4 ]
%19 = getelementptr inbounds [80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 %17
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 10
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = sext i32 %18 to i64
%24 = getelementptr inbounds [80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 %23
store i8 10, i8* %24
%25 = add nsw i32 %18, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %22, %16
%29 = tail call i32 @strlen(i8* %5)
%30 = tail call i32 @safestrcpy(i8* %0, i8* %5, i32 %29)
br label %31
31: ; preds = %1, %28
%32 = phi i8* [ getelementptr inbounds ([80 x i8], [80 x i8]* @extract_reply.replybuf, i64 0, i64 0), %28 ], [ null, %1 ]
ret i8* %32
}