#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 ap_parse(char *, char const **, char const **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *, char const *, char const *,
                          char const *);
char *strdup(char const *);
int test(const char *str) {
  char *dup = str != NULL ? strdup(str) : NULL;
  const char *a = "ADDR", *p = "PORT";
  int rc = ap_parse(dup, &a, &p);
  printf("%s `%s' `%s' `%s'\n", rc == 0 ? "PASS" : "FAIL",
         str != NULL ? str : "<NULL>", a, p);
  free(dup);
  return rc;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1169 <test+0x29>
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    1174 <test+0x34>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    1174 <test+0x34>
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <ap_parse@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edx
lea    0xe72(%rip),%rax
lea    0xe66(%rip),%rcx
cmp    $0x0,%edx
cmove  %rcx,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11da <test+0x9a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11ea <test+0xaa>
lea    0xe46(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11ea <test+0xaa>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     115a <test+0x1a>
mov    %rdi,%rbx
call   1060 <strdup@plt>
mov    %rax,%r14
jmp    1164 <test+0x24>
lea    0xec6(%rip),%rbx
xor    %r14d,%r14d
lea    0xe95(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe8e(%rip),%rax
mov    %rax,(%rsp)
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1050 <ap_parse@plt>
mov    %eax,%ebp
test   %eax,%eax
lea    0xe87(%rip),%rax
lea    0xe85(%rip),%rsi
cmove  %rax,%rsi
mov    0x8(%rsp),%rcx
mov    (%rsp),%r8
lea    0xe59(%rip),%rdi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"ADDR\00"
@.str.1 = [5 x i8] c"PORT\00"
@.str.2 = [19 x i8] c"%s `%s' `%s' `%s'\0A\00"
@.str.3 = [5 x i8] c"PASS\00"
@.str.4 = [5 x i8] c"FAIL\00"
@.str.5 = [7 x i8] c"<NULL>\00"
define i32 @test(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i8* @strdup(i8* %10)
br label %13
12: ; preds = %1
br label %13
13: ; preds = %12, %9
%14 = phi i8* [ %11, %9 ], [ null, %12 ]
store i8* %14, i8** %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %5
%15 = load i8*, i8** %3
%16 = call i32 @ap_parse(i8* %15, i8** %4, i8** %5)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%21 = load i8*, i8** %2
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = load i8*, i8** %2
br label %26
25: ; preds = %13
br label %26
26: ; preds = %25, %23
%27 = phi i8* [ %24, %23 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %25 ]
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %20, i8* %27, i8* %28, i8* %29)
%31 = load i8*, i8** %3
%32 = call i32 @free(i8* %31)
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"ADDR\00"
@.str.1 = [5 x i8] c"PORT\00"
@.str.2 = [19 x i8] c"%s `%s' `%s' `%s'\0A\00"
@.str.3 = [5 x i8] c"PASS\00"
@.str.4 = [5 x i8] c"FAIL\00"
@.str.5 = [7 x i8] c"<NULL>\00"
define i32 @test(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i8* @strdup(i8* %0)
br label %7
7: ; preds = %1, %5
%8 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %1 ], [ %0, %5 ]
%9 = phi i8* [ null, %1 ], [ %6, %5 ]
%10 = bitcast i8** %2 to i8*
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
%11 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
%12 = call i32 @ap_parse(i8* %9, i8** %2, i8** %3)
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%15 = load i8*, i8** %2
%16 = load i8*, i8** %3
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %14, i8* %8, i8* %15, i8* %16)
%18 = call i32 @free(i8* %9)
ret i32 %12
}