#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*/ STDIN_FILENO;
int /*<<< orphan*/ giveFlag();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
void handle_connection(int sock) {
  bool didPurchase = false;
  char input[50];
  printf("Debug info: Address of input buffer = %p\n", input);
  printf("Enter the name you used to purchase this program: ");
  read(STDIN_FILENO, input, 1024);
  if (didPurchase) {
    printf("Thank you for purchasing Hackersoft Powersploit!\n");
    giveFlag();
  } else {
    printf("This program has not been purchased.\n");
  }
}


x86 assembly (clang, -O0):
<handle_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
cmpl   $0x0,-0x8(%rbp)
je     119d <handle_connection+0x6d>
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <giveFlag@plt>
jmp    11ab <handle_connection+0x7b>
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_connection>:
push   %rbx
sub    $0x40,%rsp
lea    0xec4(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeda(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Debug info: Address of input buffer = %p\0A\00"
@.str.1 = [51 x i8] c"Enter the name you used to purchase this program: \00"
@STDIN_FILENO = global i32 0
@.str.2 = [50 x i8] c"Thank you for purchasing Hackersoft Powersploit!\0A\00"
@.str.3 = [38 x i8] c"This program has not been purchased.\0A\00"
define void @handle_connection(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [50 x i8]
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @STDIN_FILENO
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 1024)
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (...) @giveFlag()
br label %18
16: ; preds = %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"Debug info: Address of input buffer = %p\0A\00"
@.str.1 = [51 x i8] c"Enter the name you used to purchase this program: \00"
@STDIN_FILENO = global i32 0
@str = [37 x i8] c"This program has not been purchased.\00"
define void @handle_connection(i32 %0) {
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @STDIN_FILENO
%7 = call i32 @read(i32 %6, i8* %3, i32 1024)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
ret void
}