#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_protocol(char const *);
int validate_protocol_negate(const char *str) {
  if (!str)
    return 0;
  char proto[100];
  memset(proto, '\0', 100);
  if (sscanf(str, "!%100s", proto) != 1)
    return validate_protocol(str);
  return validate_protocol(proto);
}


x86 assembly (clang, -O0):
<validate_protocol_negate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1156 <validate_protocol_negate+0x26>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <validate_protocol_negate+0x70>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe8b(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1194 <validate_protocol_negate+0x64>
mov    -0x10(%rbp),%rdi
call   1040 <validate_protocol@plt>
mov    %eax,-0x4(%rbp)
jmp    11a0 <validate_protocol_negate+0x70>
lea    -0x80(%rbp),%rdi
call   1040 <validate_protocol@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_protocol_negate>:
test   %rdi,%rdi
je     117a <validate_protocol_negate+0x4a>
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1030 <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   1040 <validate_protocol@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
ret

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