#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*/ logmsg;

/* Variables and functions */
int /*<<< orphan*/ logging(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int socket(int, int, int);
int Socket(int family, int type, int protocal) {
  int sockfd;
  if ((sockfd = socket(family, type, protocal)) < 0) {
    perror("socket");
    return -1;
  }
  char logmsg[128];
  snprintf(logmsg, sizeof(logmsg), "Socket id = %d\n", sockfd);
  logging("lsrp-router.log", logmsg);
  return sockfd;
}


x86 assembly (clang, -O0):
<Socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1186 <Socket+0x46>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <Socket+0x7a>
lea    -0xa0(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x80,%esi
lea    0xe6b(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0xa0(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1040 <logging@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Socket>:
push   %r14
push   %rbx
sub    $0x88,%rsp
call   1060 <socket@plt>
test   %eax,%eax
js     118a <Socket+0x4a>
mov    %eax,%ebx
lea    0xeab(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x80,%esi
mov    %eax,%ecx
call   1030 <snprintf@plt>
lea    0xea2(%rip),%rdi
mov    %r14,%rsi
call   1040 <logging@plt>
mov    %ebx,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6f(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    117d <Socket+0x3d>

LLVM IR (-O0):
@.str = [7 x i8] c"socket\00"
@.str.1 = [16 x i8] c"Socket id = %d\0A\00"
@.str.2 = [16 x i8] c"lsrp-router.log\00"
define i32 @Socket(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [128 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = call i32 @socket(i32 %10, i32 %11, i32 %12)
store i32 %13, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %24
17: ; preds = %3
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%19 = load i32, i32* %8
%20 = call i32 @snprintf(i8* %18, i32 128, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%22 = call i32 @logging(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %8
store i32 %23, i32* %4
br label %24
24: ; preds = %17, %15
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@.str = [7 x i8] c"socket\00"
@.str.1 = [16 x i8] c"Socket id = %d\0A\00"
@.str.2 = [16 x i8] c"lsrp-router.log\00"
define i32 @Socket(i32 %0, i32 %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = tail call i32 @socket(i32 %0, i32 %1, i32 %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %13
9: ; preds = %3
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = call i32 @snprintf(i8* %10, i32 128, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%12 = call i32 @logging(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %13
13: ; preds = %9, %7
%14 = phi i32 [ -1, %7 ], [ %5, %9 ]
ret i32 %14
}