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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_MULTICAST_TTL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ log_error(char *, int /*<<< orphan*/);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int udpsocket_setttl(int sock, int ttl) {
  if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) {
    log_error("could not set IP_MULTICAST_TTL socket option (%s)",
              strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<udpsocket_setttl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1194 <udpsocket_setttl+0x64>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe7d(%rip),%rdi
call   1040 <log_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <udpsocket_setttl+0x6b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udpsocket_setttl>:
push   %rax
mov    %esi,0x4(%rsp)
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1163 <udpsocket_setttl+0x33>
pop    %rcx
ret
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe88(%rip),%rdi
mov    %eax,%esi
call   1040 <log_error@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@.str = [50 x i8] c"could not set IP_MULTICAST_TTL socket option (%s)\00"
@errno = global i32 0
define i32 @udpsocket_setttl(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = load i32, i32* @IPPROTO_IP
%8 = load i32, i32* @IP_MULTICAST_TTL
%9 = call i64 @setsockopt(i32 %6, i32 %7, i32 %8, i32* %5, i32 4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @log_error(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 -1, i32* %3
br label %16
15: ; preds = %2
store i32 0, i32* %3
br label %16
16: ; preds = %15, %11
%17 = load i32, i32* %3
ret i32 %17
}

LLVM IR (-O2):
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@.str = [50 x i8] c"could not set IP_MULTICAST_TTL socket option (%s)\00"
@errno = global i32 0
define i32 @udpsocket_setttl(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = load i32, i32* @IPPROTO_IP
%5 = load i32, i32* @IP_MULTICAST_TTL
%6 = call i64 @setsockopt(i32 %0, i32 %4, i32 %5, i32* %3, i32 4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @log_error(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %2, %8
%13 = phi i32 [ -1, %8 ], [ 0, %2 ]
ret i32 %13
}