#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ cpu_get_freq(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int process_get_resource(int sockfd, char *msg) {
  char buf[2048];
  memset(buf, 0, sizeof(buf));
  cpu_get_freq(buf);
  if (send(sockfd, buf, strlen(buf), 0) == -1) {
    printf("send:%s", strerror(errno));
    return -1;
  }
  if (sockfd) {
    close(sockfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<process_get_resource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
lea    -0x810(%rbp),%rdi
call   1080 <cpu_get_freq@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x81c(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
lea    -0x810(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x81c(%rbp),%edi
mov    -0x818(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    120c <process_get_resource+0x9c>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe05(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1225 <process_get_resource+0xb5>
cmpl   $0x0,-0x8(%rbp)
je     121e <process_get_resource+0xae>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_get_resource>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %edi,%ebp
mov    %rsp,%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
call   1080 <cpu_get_freq@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     11c2 <process_get_resource+0x52>
test   %ebp,%ebp
je     11e5 <process_get_resource+0x75>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    11e5 <process_get_resource+0x75>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe29(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"send:%s\00"
@errno = global i32 0
define i32 @process_get_resource(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [2048 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 2048)
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%10 = call i32 @cpu_get_freq(i8* %9)
%11 = load i32, i32* %4
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @send(i32 %11, i8* %12, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 -1, i32* %3
br label %28
21: ; preds = %2
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %4
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %24, %21
store i32 0, i32* %3
br label %28
28: ; preds = %27, %17
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [8 x i8] c"send:%s\00"
@errno = global i32 0
define i32 @process_get_resource(i32 %0, i8* nocapture readnone %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 2048)
%6 = call i32 @cpu_get_freq(i8* %4)
%7 = call i32 @strlen(i8* %4)
%8 = call i32 @send(i32 %0, i8* %4, i32 %7, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %18
14: ; preds = %2
%15 = icmp eq i32 %0, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = call i32 @close(i32 %0)
br label %18
18: ; preds = %14, %16, %10
%19 = phi i32 [ -1, %10 ], [ 0, %16 ], [ 0, %14 ]
ret i32 %19
}