#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_portrange(char const *);
int validate_portrange_negate(const char *str) {
  if (!str)
    return 0;
  char port[11];
  memset(port, '\0', 11);
  if (sscanf(str, "!%11s", port) != 1)
    return validate_portrange(str);
  return validate_portrange(port);
}


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

x86 assembly (clang, -O2):
<validate_portrange_negate>:
test   %rdi,%rdi
je     117c <validate_portrange_negate+0x4c>
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xd(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1040 <memset@plt>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
cmove  %r14,%rbx
mov    %rbx,%rdi
call   1030 <validate_portrange@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [6 x i8] c"!%11s\00"
define i32 @validate_portrange_negate(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [11 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 [11 x i8], [11 x i8]* %4, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i8 signext 0, i32 11)
%11 = load i8*, i8** %3
%12 = getelementptr inbounds [11 x i8], [11 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_portrange(i8* %16)
store i32 %17, i32* %2
br label %21
18: ; preds = %8
%19 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%20 = call i32 @validate_portrange(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"!%11s\00"
define i32 @validate_portrange_negate(i8* %0) {
%2 = alloca [11 x i8]
%3 = icmp eq i8* %0, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i8 signext 0, i32 11)
%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_portrange(i8* %9)
br label %11
11: ; preds = %1, %4
%12 = phi i32 [ %10, %4 ], [ 0, %1 ]
ret i32 %12
}