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


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

x86 assembly (clang, -O2):
<validate_port_negate>:
test   %rdi,%rdi
je     1179 <validate_port_negate+0x49>
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x3(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
lea    0xea9(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
cmove  %r14,%rbx
mov    %rbx,%rdi
call   1030 <validate_port@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
ret

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