#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*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ printf(char *, ...);
char *strdelim(char **);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, scalar_t__);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
int test_strdelim(char *line, char *var, char *val) {
  char *l;
  char *keyword;
  char *value;
  l = (char *)malloc(strlen(line) + 1);
  memset(l, 0, strlen(line) + 1);
  strncpy(l, line, strlen(line));
  printf("   strdelim( '%s', '%s', '%s')", l, var, val);
  keyword = strdelim(&l);
  value = strdelim(&l);
  free(l);
  printf(" = '%s', '%s' ", keyword, value);
  if (strlen(keyword) == strlen(var) && strlen(value) == strlen(val)) {
    if (strncmp(keyword, var, strlen(var)) == 0 &&
        strncmp(value, val, strlen(val)) == 0) {
      free(keyword);
      printf("passed\n");
      return (0);
    }
  }
  free(keyword);
  printf("failed\n");
  return (1);
}


x86 assembly (clang, -O0):
<test_strdelim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1090 <memset@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %rax,%rdx
call   1040 <strncpy@plt>
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x28(%rbp),%rdi
call   1060 <strdelim@plt>
mov    %rax,-0x30(%rbp)
lea    -0x28(%rbp),%rdi
call   1060 <strdelim@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jne    1329 <test_strdelim+0x1a9>
mov    -0x38(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
cmp    %rcx,%rax
jne    1329 <test_strdelim+0x1a9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %rax,%rdx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1324 <test_strdelim+0x1a4>
mov    -0x38(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    %rax,%rdx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1324 <test_strdelim+0x1a4>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1347 <test_strdelim+0x1c7>
jmp    1329 <test_strdelim+0x1a9>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strdelim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1080 <strlen@plt>
lea    0x1(%rax),%rdi
call   10b0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,(%rsp)
mov    %rbx,%rdi
call   1080 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbp,%rdi
xor    %esi,%esi
call   10a0 <memset@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <strncpy@plt>
lea    0xe14(%rip),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strdelim@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1060 <strdelim@plt>
mov    %rax,%r12
mov    (%rsp),%rdi
call   1030 <free@plt>
lea    0xdfa(%rip),%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r13,%rdi
call   1080 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1080 <strlen@plt>
cmp    %rax,%rbx
jne    1290 <test_strdelim+0x100>
mov    %r12,%rdi
call   1080 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1080 <strlen@plt>
cmp    %rax,%rbp
jne    1290 <test_strdelim+0x100>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1290 <test_strdelim+0x100>
mov    %r14,%rdi
call   1080 <strlen@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1050 <strncmp@plt>
test   %rax,%rax
je     12bd <test_strdelim+0x12d>
mov    $0x1,%ebp
lea    0xd92(%rip),%rbx
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1070 <puts@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
lea    0xd6f(%rip),%rbx
jmp    129c <test_strdelim+0x10c>

LLVM IR (-O0):
@.str = [31 x i8] c" strdelim( '%s', '%s', '%s')\00"
@.str.1 = [15 x i8] c" = '%s', '%s' \00"
@.str.2 = [8 x i8] c"passed\0A\00"
@.str.3 = [8 x i8] c"failed\0A\00"
define i32 @test_strdelim(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 1
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = call i32 @memset(i8* %16, i32 0, i64 %19)
%21 = load i8*, i8** %8
%22 = load i8*, i8** %5
%23 = load i8*, i8** %5
%24 = call i64 @strlen(i8* %23)
%25 = call i32 @strncpy(i8* %21, i8* %22, i64 %24)
%26 = load i8*, i8** %8
%27 = load i8*, i8** %6
%28 = load i8*, i8** %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %27, i8* %28)
%30 = call i8* @strdelim(i8** %8)
store i8* %30, i8** %9
%31 = call i8* @strdelim(i8** %8)
store i8* %31, i8** %10
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %9
%35 = load i8*, i8** %10
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %35)
%37 = load i8*, i8** %9
%38 = call i64 @strlen(i8* %37)
%39 = load i8*, i8** %6
%40 = call i64 @strlen(i8* %39)
%41 = icmp eq i64 %38, %40
br i1 %41, label %42, label %67
42: ; preds = %3
%43 = load i8*, i8** %10
%44 = call i64 @strlen(i8* %43)
%45 = load i8*, i8** %7
%46 = call i64 @strlen(i8* %45)
%47 = icmp eq i64 %44, %46
br i1 %47, label %48, label %67
48: ; preds = %42
%49 = load i8*, i8** %9
%50 = load i8*, i8** %6
%51 = load i8*, i8** %6
%52 = call i64 @strlen(i8* %51)
%53 = call i64 @strncmp(i8* %49, i8* %50, i64 %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %66
55: ; preds = %48
%56 = load i8*, i8** %10
%57 = load i8*, i8** %7
%58 = load i8*, i8** %7
%59 = call i64 @strlen(i8* %58)
%60 = call i64 @strncmp(i8* %56, i8* %57, i64 %59)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = load i8*, i8** %9
%64 = call i32 @free(i8* %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %71
66: ; preds = %55, %48
br label %67
67: ; preds = %66, %42, %3
%68 = load i8*, i8** %9
%69 = call i32 @free(i8* %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %4
br label %71
71: ; preds = %67, %62
%72 = load i32, i32* %4
ret i32 %72
}

LLVM IR (-O2):
@.str = [31 x i8] c" strdelim( '%s', '%s', '%s')\00"
@.str.1 = [15 x i8] c" = '%s', '%s' \00"
@str = [7 x i8] c"failed\00"
@str.4 = [7 x i8] c"passed\00"
define i32 @test_strdelim(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add nsw i64 %6, 1
%8 = tail call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = add nsw i64 %10, 1
%12 = tail call i32 @memset(i8* %9, i32 0, i64 %11)
%13 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%14 = tail call i32 @strncpy(i8* %9, i8* %0, i64 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %1, i8* %2)
%16 = call i8* @strdelim(i8** %4)
%17 = call i8* @strdelim(i8** %4)
%18 = load i8*, i8** %4
%19 = call i32 @free(i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
%21 = call i64 @strlen(i8* dereferenceable(1) %16)
%22 = call i64 @strlen(i8* dereferenceable(1) %1)
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %3
%25 = call i64 @strlen(i8* dereferenceable(1) %17)
%26 = call i64 @strlen(i8* dereferenceable(1) %2)
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = call i64 @strncmp(i8* %16, i8* %1, i64 %21)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = call i64 @strlen(i8* dereferenceable(1) %2)
%33 = call i64 @strncmp(i8* %17, i8* %2, i64 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %28, %31, %24, %3
br label %36
36: ; preds = %31, %35
%37 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0), %35 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0), %31 ]
%38 = phi i32 [ 1, %35 ], [ 0, %31 ]
%39 = call i32 @free(i8* %16)
%40 = call i32 @puts(i8* dereferenceable(1) %37)
ret i32 %38
}