#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 */
scalar_t__ strcmp(char *, char const *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strtok(char *, char *);
int /*<<< orphan*/ warn(char *);
int /*<<< orphan*/ warnx(char *, char const *);
int parse_string(char *line, const char *key, char *result,
                 const size_t result_len) {
  char *value;
  size_t value_len;
  if (strcmp(strtok(line, "="), key) == 0) {
    if ((value = strtok(NULL, "\n")) == NULL) {
      warn("strtok");
      return -1;
    }
    value_len = strlen(value);
    if (value_len >= result_len - 1) {
      warnx("%s value too long", key);
      return -1;
    }
    strncpy(result, value, value_len);
    result[value_len] = '\0';
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<parse_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    123b <parse_string+0xdb>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe59(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11d4 <parse_string+0x74>
lea    0xe41(%rip),%rdi
call   1040 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1242 <parse_string+0xe2>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jb     1212 <parse_string+0xb2>
mov    -0x18(%rbp),%rsi
lea    0xe0a(%rip),%rdi
call   1060 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1242 <parse_string+0xe2>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    1242 <parse_string+0xe2>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xe85(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     11a6 <parse_string+0x46>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe55(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     11e7 <parse_string+0x87>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
add    $0xffffffffffffffff,%r15
cmp    %r15,%rax
jae    11f5 <parse_string+0x95>
mov    %rax,%r13
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%r13,1)
xor    %ebp,%ebp
jmp    1195 <parse_string+0x35>
lea    0xe16(%rip),%rdi
call   1040 <warn@plt>
jmp    1195 <parse_string+0x35>
lea    0xe0f(%rip),%rdi
mov    %rbx,%rsi
call   1060 <warnx@plt>
jmp    1195 <parse_string+0x35>

LLVM IR (-O0):
@.str = [2 x i8] c"=\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [7 x i8] c"strtok\00"
@.str.3 = [18 x i8] c"%s value too long\00"
define i32 @parse_string(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = load i8*, i8** %6
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %7
%15 = call i64 @strcmp(i8* %13, i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %40
17: ; preds = %4
%18 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %10
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %41
22: ; preds = %17
%23 = load i8*, i8** %10
%24 = call i64 @strlen(i8* %23)
store i64 %24, i64* %11
%25 = load i64, i64* %11
%26 = load i64, i64* %9
%27 = sub i64 %26, 1
%28 = icmp uge i64 %25, %27
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i8*, i8** %7
%31 = call i32 @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %30)
store i32 -1, i32* %5
br label %41
32: ; preds = %22
%33 = load i8*, i8** %8
%34 = load i8*, i8** %10
%35 = load i64, i64* %11
%36 = call i32 @strncpy(i8* %33, i8* %34, i64 %35)
%37 = load i8*, i8** %8
%38 = load i64, i64* %11
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8 0, i8* %39
store i32 0, i32* %5
br label %41
40: ; preds = %4
store i32 -1, i32* %5
br label %41
41: ; preds = %40, %32, %29, %20
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@.str = [2 x i8] c"=\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [7 x i8] c"strtok\00"
@.str.3 = [18 x i8] c"%s value too long\00"
define i32 @parse_string(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @strcmp(i8* %5, i8* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %22
13: ; preds = %8
%14 = tail call i64 @strlen(i8* %9)
%15 = add i64 %3, -1
%16 = icmp ult i64 %14, %15
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %22
19: ; preds = %13
%20 = tail call i32 @strncpy(i8* %2, i8* %9, i64 %14)
%21 = getelementptr inbounds i8, i8* %2, i64 %14
store i8 0, i8* %21
br label %22
22: ; preds = %4, %19, %17, %11
%23 = phi i32 [ -1, %11 ], [ -1, %17 ], [ 0, %19 ], [ -1, %4 ]
ret i32 %23
}