#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*/ memset(char *, char, int);
int sscanf(char const *, char *, char *);
int validate_ipv6(char const *);
int validate_ipv6_negate(const char *str) {
  if (!str)
    return 0;
  char ipv6[39];
  memset(ipv6, '\0', 39);
  if (sscanf(str, "!%39s", ipv6) != 1)
    return validate_ipv6(str);
  return validate_ipv6(ipv6);
}


x86 assembly (clang, -O0):
<validate_ipv6_negate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <validate_ipv6_negate+0x23>
movl   $0x0,-0x4(%rbp)
jmp    119d <validate_ipv6_negate+0x6d>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x27,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe8e(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1191 <validate_ipv6_negate+0x61>
mov    -0x10(%rbp),%rdi
call   1030 <validate_ipv6@plt>
mov    %eax,-0x4(%rbp)
jmp    119d <validate_ipv6_negate+0x6d>
lea    -0x40(%rbp),%rdi
call   1030 <validate_ipv6@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_ipv6_negate>:
test   %rdi,%rdi
je     117a <validate_ipv6_negate+0x4a>
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x27,%edx
call   1040 <memset@plt>
lea    0xea8(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
cmove  %r14,%rbx
mov    %rbx,%rdi
call   1030 <validate_ipv6@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [6 x i8] c"!%39s\00"
define i32 @validate_ipv6_negate(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [39 x i8]
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 0, i32* %2
br label %21
8: ; preds = %1
%9 = getelementptr inbounds [39 x i8], [39 x i8]* %4, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i8 signext 0, i32 39)
%11 = load i8*, i8** %3
%12 = getelementptr inbounds [39 x i8], [39 x i8]* %4, i64 0, i64 0
%13 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = call i32 @validate_ipv6(i8* %16)
store i32 %17, i32* %2
br label %21
18: ; preds = %8
%19 = getelementptr inbounds [39 x i8], [39 x i8]* %4, i64 0, i64 0
%20 = call i32 @validate_ipv6(i8* %19)
store i32 %20, i32* %2
br label %21
21: ; preds = %18, %15, %7
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [6 x i8] c"!%39s\00"
define i32 @validate_ipv6_negate(i8* %0) {
%2 = alloca [39 x i8]
%3 = icmp eq i8* %0, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = getelementptr inbounds [39 x i8], [39 x i8]* %2, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i8 signext 0, i32 39)
%7 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5)
%8 = icmp eq i32 %7, 1
%9 = select i1 %8, i8* %5, i8* %0
%10 = call i32 @validate_ipv6(i8* %9)
br label %11
11: ; preds = %1, %4
%12 = phi i32 [ %10, %4 ], [ 0, %1 ]
ret i32 %12
}