#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__ getsysctl(char *, char **);
int /*<<< orphan*/ printf(char *, char *, char *);
scalar_t__ setsysctl(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ weprintf(char *, char *);
int parsepair(char *pair) {
  char *p;
  char *variable;
  char *value;
  for (p = pair; *p; p++) {
    if (p[0] == '.' && p[1] == '.') {
      weprintf("malformed input: %s\n", pair);
      return -1;
    }
  }
  p = strchr(pair, '=');
  if (p) {
    if (p[1] == '\0') {
      weprintf("malformed input: %s\n", pair);
      return -1;
    }
    *p = '\0';
    value = &p[1];
  } else {
    value = NULL;
  }
  variable = pair;
  if (value) {
    if (setsysctl(variable, value) < 0) {
      weprintf("failed to set sysctl for %s\n", variable);
      return -1;
    }
  } else {
    if (getsysctl(variable, &value) < 0) {
      weprintf("failed to get sysctl for %s\n", variable);
      return -1;
    }
    printf("%s = %s\n", variable, value);
    free(value);
  }
  return 0;
}


x86 assembly (clang, -O0):
<parsepair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d4 <parsepair+0x74>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11be <parsepair+0x5e>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    11be <parsepair+0x5e>
mov    -0x10(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1080 <weprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <parsepair+0x180>
jmp    11c3 <parsepair+0x63>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1174 <parsepair+0x14>
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1236 <parsepair+0xd6>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    121e <parsepair+0xbe>
mov    -0x10(%rbp),%rsi
lea    0xdf3(%rip),%rdi
call   1080 <weprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <parsepair+0x180>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    123e <parsepair+0xde>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1289 <parsepair+0x129>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <setsysctl@plt>
cmp    $0x0,%rax
jge    1284 <parsepair+0x124>
mov    -0x20(%rbp),%rsi
lea    0xda2(%rip),%rdi
call   1080 <weprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <parsepair+0x180>
jmp    12d9 <parsepair+0x179>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <getsysctl@plt>
cmp    $0x0,%rax
jge    12bc <parsepair+0x15c>
mov    -0x20(%rbp),%rsi
lea    0xd87(%rip),%rdi
call   1080 <weprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <parsepair+0x180>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xd84(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsepair>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x1(%rdi),%rax
jmp    1179 <parsepair+0x19>
xchg   %ax,%ax
cmpb   $0x2e,(%rax)
je     11c3 <parsepair+0x63>
add    $0x1,%rax
movzbl -0x1(%rax),%ecx
cmp    $0x2e,%cl
je     1170 <parsepair+0x10>
test   %cl,%cl
jne    1175 <parsepair+0x15>
mov    %rbx,%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11dd <parsepair+0x7d>
cmpb   $0x0,0x1(%rax)
je     11c3 <parsepair+0x63>
mov    %rax,%rsi
add    $0x1,%rsi
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1060 <setsysctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    11d7 <parsepair+0x77>
lea    0xe54(%rip),%rdi
jmp    11ca <parsepair+0x6a>
lea    0xe36(%rip),%rdi
mov    %rbx,%rsi
call   1080 <weprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <getsysctl@plt>
test   %rax,%rax
js     121a <parsepair+0xba>
mov    0x8(%rsp),%rdx
lea    0xe4b(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11d7 <parsepair+0x77>
lea    0xe11(%rip),%rdi
jmp    11ca <parsepair+0x6a>

LLVM IR (-O0):
@.str = [21 x i8] c"malformed input: %s\0A\00"
@.str.1 = [29 x i8] c"failed to set sysctl for %s\0A\00"
@.str.2 = [29 x i8] c"failed to get sysctl for %s\0A\00"
@.str.3 = [9 x i8] c"%s = %s\0A\00"
define i32 @parsepair(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
store i8* %7, i8** %4
br label %8
8: ; preds = %28, %1
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 46
br i1 %17, label %18, label %27
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 46
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i8*, i8** %3
%26 = call i32 @weprintf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 -1, i32* %2
br label %77
27: ; preds = %18, %12
br label %28
28: ; preds = %27
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
br label %8
31: ; preds = %8
%32 = load i8*, i8** %3
%33 = call i8* @strchr(i8* %32, i8 signext 61)
store i8* %33, i8** %4
%34 = load i8*, i8** %4
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %49
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i8*, i8** %3
%44 = call i32 @weprintf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %43)
store i32 -1, i32* %2
br label %77
45: ; preds = %36
%46 = load i8*, i8** %4
store i8 0, i8* %46
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %48, i8** %6
br label %50
49: ; preds = %31
store i8* null, i8** %6
br label %50
50: ; preds = %49, %45
%51 = load i8*, i8** %3
store i8* %51, i8** %5
%52 = load i8*, i8** %6
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %63
54: ; preds = %50
%55 = load i8*, i8** %5
%56 = load i8*, i8** %6
%57 = call i64 @setsysctl(i8* %55, i8* %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i8*, i8** %5
%61 = call i32 @weprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %60)
store i32 -1, i32* %2
br label %77
62: ; preds = %54
br label %76
63: ; preds = %50
%64 = load i8*, i8** %5
%65 = call i64 @getsysctl(i8* %64, i8** %6)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i8*, i8** %5
%69 = call i32 @weprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %68)
store i32 -1, i32* %2
br label %77
70: ; preds = %63
%71 = load i8*, i8** %5
%72 = load i8*, i8** %6
%73 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %71, i8* %72)
%74 = load i8*, i8** %6
%75 = call i32 @free(i8* %74)
br label %76
76: ; preds = %70, %62
store i32 0, i32* %2
br label %77
77: ; preds = %76, %67, %59, %42, %24
%78 = load i32, i32* %2
ret i32 %78
}

LLVM IR (-O2):
@.str = [21 x i8] c"malformed input: %s\0A\00"
@.str.1 = [29 x i8] c"failed to set sysctl for %s\0A\00"
@.str.2 = [29 x i8] c"failed to get sysctl for %s\0A\00"
@.str.3 = [9 x i8] c"%s = %s\0A\00"
define i32 @parsepair(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
br label %4
4: ; preds = %13, %1
%5 = phi i8* [ %0, %1 ], [ %14, %13 ]
%6 = load i8, i8* %5
switch i8 %6, label %13 [
i8 0, label %15
i8 46, label %7
]
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 46
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @weprintf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %39
13: ; preds = %4, %7
%14 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
15: ; preds = %4
%16 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 61)
%17 = icmp eq i8* %16, null
br i1 %17, label %29, label %18
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %16, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @weprintf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %39
24: ; preds = %18
store i8 0, i8* %16
%25 = tail call i64 @setsysctl(i8* %0, i8* %19)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = tail call i32 @weprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %39
29: ; preds = %15
store i8* null, i8** %2
%30 = call i64 @getsysctl(i8* %0, i8** %2)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @weprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %39
34: ; preds = %29
%35 = load i8*, i8** %2
%36 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %35)
%37 = load i8*, i8** %2
%38 = call i32 @free(i8* %37)
br label %39
39: ; preds = %34, %24, %32, %27, %22, %11
%40 = phi i32 [ -1, %11 ], [ -1, %22 ], [ -1, %27 ], [ -1, %32 ], [ 0, %24 ], [ 0, %34 ]
ret i32 %40
}