#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 */
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
void parse_line(const char *head, char *buf, size_t len, FILE *f) {
  char line[4096];
  fgets(line, sizeof(line), f);
  line[strlen(line) - 1] = '\0';
  if (strncmp(line, head, strlen(head)) == 0) {
    strncpy(buf, line + strlen(head), len);
  } else {
    strncpy(buf, line, len);
  }
}


x86 assembly (clang, -O0):
<parse_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <fgets@plt>
lea    -0x1020(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1030(%rbp),%rdi
mov    -0x1028(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    120d <parse_line+0xcd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x1038(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1040(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1040(%rbp),%rsi
mov    -0x1038(%rbp),%rdi
cltq
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
jmp    1221 <parse_line+0xe1>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %rcx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11a1 <parse_line+0x61>
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @parse_line(i8* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca [4096 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%11 = load i32*, i32** %8
%12 = call i32 @fgets(i8* %10, i32 4096, i32* %11)
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%19 = load i8*, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = call i64 @strncmp(i8* %18, i8* %19, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %4
%25 = load i8*, i8** %6
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i64, i64* %7
%32 = call i32 @strncpy(i8* %25, i8* %30, i64 %31)
br label %38
33: ; preds = %4
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%36 = load i64, i64* %7
%37 = call i32 @strncpy(i8* %34, i8* %35, i64 %36)
br label %38
38: ; preds = %33, %24
ret void
}

LLVM IR (-O2):
define void @parse_line(i8* %0, i8* %1, i64 %2, i32* nocapture %3) {
%5 = alloca [4096 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%7 = call i32 @fgets(i8* %6, i32 4096, i32* %3)
%8 = call i32 @strlen(i8* %6)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @strlen(i8* %0)
%13 = call i64 @strncmp(i8* %6, i8* %0, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %4
%16 = call i32 @strlen(i8* %0)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %17
br label %19
19: ; preds = %4, %15
%20 = phi i8* [ %18, %15 ], [ %6, %4 ]
%21 = call i32 @strncpy(i8* %1, i8* %20, i64 %2)
ret void
}