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

/* Variables and functions */
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ logging(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *);
int Bind(int sockfd, struct sockaddr_in sockaddr) {
  int n;
  if ((n = bind(sockfd, (struct sockaddr *)&sockaddr,
                sizeof(struct sockaddr))) < 0) {
    perror("bind");
    return -1;
  }
  char logmsg[128];
  snprintf(logmsg, sizeof(logmsg), "Bind success!\n");
  logging("lsrp-router.log", logmsg);
  return n;
}


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

x86 assembly (clang, -O2):
<Bind>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %esi,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1050 <bind@plt>
test   %eax,%eax
js     1198 <Bind+0x58>
mov    %eax,%ebx
lea    0xe9b(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x80,%esi
call   1030 <snprintf@plt>
lea    0xe91(%rip),%rdi
mov    %r14,%rsi
call   1040 <logging@plt>
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe61(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebx
jmp    118b <Bind+0x4b>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"bind\00"
@.str.1 = [15 x i8] c"Bind success!\0A\00"
@.str.2 = [16 x i8] c"lsrp-router.log\00"
define i32 @Bind(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [128 x i8]
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %1, i32* %5
%6 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%7 = call i32 @bind(i32 %0, %struct.sockaddr* %6, i32 4)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %15
11: ; preds = %2
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%13 = call i32 @snprintf(i8* %12, i32 128, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @logging(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %15
15: ; preds = %11, %9
%16 = phi i32 [ -1, %9 ], [ %7, %11 ]
ret i32 %16
}