#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 close(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
void StopServer(int sockfd) {
  int end;
  printf("> Stopping Server...\n");
  printf("\n");
  if (sockfd < 0) {
    printf("Invalid Socket File Descriptor, exiting....\n");
    return;
  }
  if ((end = close(sockfd)) < 0) {
    perror("  ERROR: Close Failed");
    printf("  Exiting Server with Error\n");
  } else {
    printf("> Server Stopped\n");
    printf("\n");
  }
  return;
}


x86 assembly (clang, -O0):
<StopServer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
lea    0xef3(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
jge    116e <StopServer+0x3e>
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <StopServer+0x8c>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    119f <StopServer+0x6f>
lea    0xeba(%rip),%rdi
call   1050 <perror@plt>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
jmp    11b7 <StopServer+0x87>
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <StopServer+0x8c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StopServer>:
push   %rbx
mov    %edi,%ebx
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %ebx,%ebx
js     117f <StopServer+0x3f>
mov    %ebx,%edi
call   1050 <close@plt>
test   %eax,%eax
js     118c <StopServer+0x4c>
lea    0xebc(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>
lea    0xed2(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>
lea    0xe6d(%rip),%rdi
call   1060 <perror@plt>
lea    0xe9d(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"> Stopping Server...\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [45 x i8] c"Invalid Socket File Descriptor, exiting....\0A\00"
@.str.3 = [22 x i8] c" ERROR: Close Failed\00"
@.str.4 = [29 x i8] c" Exiting Server with Error\0A\00"
@.str.5 = [18 x i8] c"> Server Stopped\0A\00"
define void @StopServer(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %21
10: ; preds = %1
%11 = load i32, i32* %2
%12 = call i32 @close(i32 %11)
store i32 %12, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %20
17: ; preds = %10
%18 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %14
br label %21
21: ; preds = %20, %8
ret void
}

LLVM IR (-O2):
@.str.3 = [22 x i8] c" ERROR: Close Failed\00"
@str = [21 x i8] c"> Stopping Server...\00"
@str.6 = [17 x i8] c"> Server Stopped\00"
@str.7 = [28 x i8] c" Exiting Server with Error\00"
@str.8 = [44 x i8] c"Invalid Socket File Descriptor, exiting....\00"
define void @StopServer(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @putchar(i32 10)
%4 = icmp slt i32 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.8, i64 0, i64 0))
br label %16
7: ; preds = %1
%8 = tail call i32 @close(i32 %0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0))
br label %16
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
%15 = tail call i32 @putchar(i32 10)
br label %16
16: ; preds = %10, %13, %5
ret void
}