#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 *find_spaces(char *);
char *skip_spaces(char *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int extract_fields(char *line, char *key, char *value) {
  if (line[0] == '#') {
    return (3);
  }
  char *sep = find_spaces(line);
  if (!sep) {
    return (1);
  }
  if (sep - line + 1 > 40) {
    return (2);
  }
  strncpy(key, line, sep - line);
  key[sep - line] = 0;
  line = skip_spaces(sep);
  if (sep - line + 1 > 256) {
    return (2);
  }
  strncpy(value, line, strlen(line));
  value[strlen(line)] = 0;
  return (0);
}


x86 assembly (clang, -O0):
<extract_fields>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1170 <extract_fields+0x30>
movl   $0x3,-0x4(%rbp)
jmp    1264 <extract_fields+0x124>
mov    -0x10(%rbp),%rdi
call   1060 <find_spaces@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1194 <extract_fields+0x54>
movl   $0x1,-0x4(%rbp)
jmp    1264 <extract_fields+0x124>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
cmp    $0x28,%rax
jle    11b9 <extract_fields+0x79>
movl   $0x2,-0x4(%rbp)
jmp    1264 <extract_fields+0x124>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
sub    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1050 <skip_spaces@plt>
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
cmp    $0x100,%rax
jle    1218 <extract_fields+0xd8>
movl   $0x2,-0x4(%rbp)
jmp    1264 <extract_fields+0x124>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_fields>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x3,%r13d
cmpb   $0x23,(%rdi)
je     11da <extract_fields+0x9a>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <find_spaces@plt>
test   %rax,%rax
je     11d4 <extract_fields+0x94>
mov    %rax,%r12
mov    %rax,%rbp
sub    %rbx,%rbp
mov    $0x2,%r13d
cmp    $0x27,%rbp
jg     11da <extract_fields+0x9a>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbp,1)
mov    %r12,%rdi
call   1050 <skip_spaces@plt>
sub    %rax,%r12
cmp    $0xff,%r12
jg     11da <extract_fields+0x9a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
xor    %r13d,%r13d
jmp    11da <extract_fields+0x9a>
mov    $0x1,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @extract_fields(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 35
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 3, i32* %4
br label %66
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i8* @find_spaces(i8* %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %15
store i32 1, i32* %4
br label %66
21: ; preds = %15
%22 = load i8*, i8** %8
%23 = load i8*, i8** %5
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = add nsw i64 %26, 1
%28 = icmp sgt i64 %27, 40
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 2, i32* %4
br label %66
30: ; preds = %21
%31 = load i8*, i8** %6
%32 = load i8*, i8** %5
%33 = load i8*, i8** %8
%34 = load i8*, i8** %5
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = call i32 @strncpy(i8* %31, i8* %32, i64 %37)
%39 = load i8*, i8** %6
%40 = load i8*, i8** %8
%41 = load i8*, i8** %5
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = getelementptr inbounds i8, i8* %39, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %8
%47 = call i8* @skip_spaces(i8* %46)
store i8* %47, i8** %5
%48 = load i8*, i8** %8
%49 = load i8*, i8** %5
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
%53 = add nsw i64 %52, 1
%54 = icmp sgt i64 %53, 256
br i1 %54, label %55, label %56
55: ; preds = %30
store i32 2, i32* %4
br label %66
56: ; preds = %30
%57 = load i8*, i8** %7
%58 = load i8*, i8** %5
%59 = load i8*, i8** %5
%60 = call i64 @strlen(i8* %59)
%61 = call i32 @strncpy(i8* %57, i8* %58, i64 %60)
%62 = load i8*, i8** %7
%63 = load i8*, i8** %5
%64 = call i64 @strlen(i8* %63)
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
store i32 0, i32* %4
br label %66
66: ; preds = %56, %55, %29, %20, %14
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
define i32 @extract_fields(i8* %0, i8* %1, i8* %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 35
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = tail call i8* @find_spaces(i8* %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %26, label %9
9: ; preds = %6
%10 = ptrtoint i8* %7 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = icmp sgt i64 %12, 39
br i1 %13, label %26, label %14
14: ; preds = %9
%15 = tail call i32 @strncpy(i8* %1, i8* %0, i64 %12)
%16 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 0, i8* %16
%17 = tail call i8* @skip_spaces(i8* %7)
%18 = ptrtoint i8* %17 to i64
%19 = sub i64 %10, %18
%20 = icmp sgt i64 %19, 255
br i1 %20, label %26, label %21
21: ; preds = %14
%22 = tail call i64 @strlen(i8* dereferenceable(1) %17)
%23 = tail call i32 @strncpy(i8* %2, i8* %17, i64 %22)
%24 = tail call i64 @strlen(i8* dereferenceable(1) %17)
%25 = getelementptr inbounds i8, i8* %2, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %21, %6, %9, %14, %3
%27 = phi i32 [ 3, %3 ], [ 0, %21 ], [ 1, %6 ], [ 2, %9 ], [ 2, %14 ]
ret i32 %27
}