#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
scalar_t__ assert_true(int, unsigned int, char *);
int drop_shell_backdoor(int, struct sockaddr *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
void test_drop_shell_backdoor(unsigned int *count, unsigned int *total) {
  struct sockaddr_in addr;
  memset(&addr, 0, sizeof(addr));
  *count +=
      assert_true(drop_shell_backdoor(99, (struct sockaddr *)&addr) == 99,
                  ++(*total), "drop_shell_backdoor(99, misc-sockaddr) == 99");
  addr.sin_port = htons((64830));
  *count += assert_true(
      drop_shell_backdoor(99, (struct sockaddr *)&addr) == -1, ++(*total),
      "drop_shell_backdoor(99, backdoor-port-sockaddr) == -1");
}


x86 assembly (clang, -O0):
<test_drop_shell_backdoor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0x18(%rbp),%rsi
mov    $0x63,%edi
call   1040 <drop_shell_backdoor@plt>
cmp    $0x63,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
add    $0x1,%esi
mov    %esi,(%rax)
lea    0xe75(%rip),%rdx
call   1030 <assert_true@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    %rdx,%rcx
mov    %ecx,(%rax)
mov    $0xfd3e,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rsi
mov    $0x63,%edi
call   1040 <drop_shell_backdoor@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
add    $0x1,%esi
mov    %esi,(%rax)
lea    0xe57(%rip),%rdx
call   1030 <assert_true@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    %rdx,%rcx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_drop_shell_backdoor>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    $0x63,%edi
mov    %r15,%rsi
call   1040 <drop_shell_backdoor@plt>
xor    %edi,%edi
cmp    $0x63,%eax
sete   %dil
mov    (%rbx),%esi
add    $0x1,%esi
mov    %esi,(%rbx)
lea    0xe79(%rip),%rdx
call   1030 <assert_true@plt>
add    %eax,(%r14)
mov    $0xfd3e,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    $0x63,%edi
mov    %r15,%rsi
call   1040 <drop_shell_backdoor@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
mov    (%rbx),%esi
add    $0x1,%esi
mov    %esi,(%rbx)
lea    0xe6c(%rip),%rdx
call   1030 <assert_true@plt>
add    %eax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [45 x i8] c"drop_shell_backdoor(99, misc-sockaddr) == 99\00"
@.str.1 = [54 x i8] c"drop_shell_backdoor(99, backdoor-port-sockaddr) == -1\00"
define void @test_drop_shell_backdoor(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca %struct.sockaddr_in
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 4)
%7 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%8 = call i32 @drop_shell_backdoor(i32 99, %struct.sockaddr* %7)
%9 = icmp eq i32 %8, 99
%10 = zext i1 %9 to i32
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = add i32 %12, 1
store i32 %13, i32* %11
%14 = call i64 @assert_true(i32 %10, i32 %13, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%15 = load i32*, i32** %3
%16 = load i32, i32* %15
%17 = zext i32 %16 to i64
%18 = add nsw i64 %17, %14
%19 = trunc i64 %18 to i32
store i32 %19, i32* %15
%20 = call i32 @htons(i32 64830)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%23 = call i32 @drop_shell_backdoor(i32 99, %struct.sockaddr* %22)
%24 = icmp eq i32 %23, -1
%25 = zext i1 %24 to i32
%26 = load i32*, i32** %4
%27 = load i32, i32* %26
%28 = add i32 %27, 1
store i32 %28, i32* %26
%29 = call i64 @assert_true(i32 %25, i32 %28, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32*, i32** %3
%31 = load i32, i32* %30
%32 = zext i32 %31 to i64
%33 = add nsw i64 %32, %29
%34 = trunc i64 %33 to i32
store i32 %34, i32* %30
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [45 x i8] c"drop_shell_backdoor(99, misc-sockaddr) == 99\00"
@.str.1 = [54 x i8] c"drop_shell_backdoor(99, backdoor-port-sockaddr) == -1\00"
define void @test_drop_shell_backdoor(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 4)
%6 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%7 = call i32 @drop_shell_backdoor(i32 99, %struct.sockaddr* %6)
%8 = icmp eq i32 %7, 99
%9 = zext i1 %8 to i32
%10 = load i32, i32* %1
%11 = add i32 %10, 1
store i32 %11, i32* %1
%12 = call i64 @assert_true(i32 %9, i32 %11, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %0
%14 = trunc i64 %12 to i32
%15 = add i32 %13, %14
store i32 %15, i32* %0
%16 = call i32 @htons(i32 64830)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %16, i32* %17
%18 = call i32 @drop_shell_backdoor(i32 99, %struct.sockaddr* %6)
%19 = icmp eq i32 %18, -1
%20 = zext i1 %19 to i32
%21 = load i32, i32* %1
%22 = add i32 %21, 1
store i32 %22, i32* %1
%23 = call i64 @assert_true(i32 %20, i32 %22, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* %0
%25 = trunc i64 %23 to i32
%26 = add i32 %24, %25
store i32 %26, i32* %0
ret void
}