#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 scalar_t__ in_port_t;

/* Variables and functions */
char *getenv(char *);
char *strchr(char *, char);
scalar_t__ strtol(char *, char **, int);
int parse_env(in_port_t *from_port, in_port_t *to_port) {
  char *rebind_port_env = getenv("REBIND_PORT"), *sep = NULL, *to_port_c = NULL;
  if (NULL == rebind_port_env)
    return -1;
  if (NULL == (sep = strchr(rebind_port_env, ':')))
    return -1;
  *sep = 0;
  to_port_c = sep + 1;
  *from_port = (in_port_t)strtol(rebind_port_env, &sep, 10);
  if (*sep != '\0')
    return -1;
  *to_port = (in_port_t)strtol(to_port_c, &sep, 10);
  if (*sep != '\0')
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<parse_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xeb9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1178 <parse_env+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <parse_env+0xfe>
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11a4 <parse_env+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <parse_env+0xfe>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ef <parse_env+0xbf>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <parse_env+0xfe>
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1227 <parse_env+0xf7>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <parse_env+0xfe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_env>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeb7(%rip),%rdi
call   1030 <getenv@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
je     11bd <parse_env+0x8d>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     11bd <parse_env+0x8d>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,(%r15)
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    11bd <parse_env+0x8d>
add    $0x1,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,(%r14)
mov    0x8(%rsp),%rax
xor    %ecx,%ecx
cmp    (%rax),%cl
sbb    %r12d,%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"REBIND_PORT\00"
define i32 @parse_env(i64* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i64* %0, i64** %4
store i64* %1, i64** %5
%9 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
%10 = load i8*, i8** %6
%11 = icmp eq i8* null, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %40
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = call i8* @strchr(i8* %14, i8 signext 58)
store i8* %15, i8** %7
%16 = icmp eq i8* null, %15
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %3
br label %40
18: ; preds = %13
%19 = load i8*, i8** %7
store i8 0, i8* %19
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %8
%22 = load i8*, i8** %6
%23 = call i64 @strtol(i8* %22, i8** %7, i32 10)
%24 = load i64*, i64** %4
store i64 %23, i64* %24
%25 = load i8*, i8** %7
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %18
store i32 -1, i32* %3
br label %40
30: ; preds = %18
%31 = load i8*, i8** %8
%32 = call i64 @strtol(i8* %31, i8** %7, i32 10)
%33 = load i64*, i64** %5
store i64 %32, i64* %33
%34 = load i8*, i8** %7
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %30
store i32 -1, i32* %3
br label %40
39: ; preds = %30
store i32 0, i32* %3
br label %40
40: ; preds = %39, %38, %29, %17, %12
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [12 x i8] c"REBIND_PORT\00"
define i32 @parse_env(i64* nocapture writeonly %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = bitcast i8** %3 to i8*
%6 = icmp eq i8* %4, null
br i1 %6, label %22, label %7
7: ; preds = %2
%8 = tail call i8* @strchr(i8* %4, i8 signext 58)
store i8* %8, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %22, label %10
10: ; preds = %7
store i8 0, i8* %8
%11 = call i64 @strtol(i8* %4, i8** %3, i32 10)
store i64 %11, i64* %0
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = getelementptr inbounds i8, i8* %8, i64 1
%17 = call i64 @strtol(i8* %16, i8** %3, i32 10)
store i64 %17, i64* %1
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
%21 = sext i1 %20 to i32
br label %22
22: ; preds = %15, %10, %7, %2
%23 = phi i32 [ -1, %2 ], [ -1, %7 ], [ -1, %10 ], [ %21, %15 ]
ret i32 %23
}