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

/* Variables and functions */
int /*<<< orphan*/ IP_MULTICAST_TTL;
int /*<<< orphan*/ SOL_IP;
int errno;
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
               int /*<<< orphan*/ *, int);
int setsock_multicast_ttl(int sock, uint8_t ttl) {
  int err = 0;
  err = setsockopt(sock, SOL_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
  if (err < 0) {
    err = -errno;
    perror("setsockopt IP_MULTICAST_TTL");
  }
  return err;
}


x86 assembly (clang, -O0):
<setsock_multicast_ttl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eb9(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1180 <setsock_multicast_ttl+0x60>
xor    %eax,%eax
mov    0x2e61(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0xc(%rbp)
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setsock_multicast_ttl>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,0xc(%rsp)
mov    0x2ec8(%rip),%rax
mov    (%rax),%esi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1159 <setsock_multicast_ttl+0x39>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e70(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
lea    0xe95(%rip),%rdi
call   1040 <perror@plt>
jmp    1151 <setsock_multicast_ttl+0x31>

LLVM IR (-O0):
@SOL_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@errno = global i32 0
@.str = [28 x i8] c"setsockopt IP_MULTICAST_TTL\00"
define i32 @setsock_multicast_ttl(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = load i32, i32* @SOL_IP
%8 = load i32, i32* @IP_MULTICAST_TTL
%9 = call i32 @setsockopt(i32 %6, i32 %7, i32 %8, i32* %4, i32 4)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @errno
%14 = sub nsw i32 0, %13
store i32 %14, i32* %5
%15 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %12, %2
%17 = load i32, i32* %5
ret i32 %17
}

LLVM IR (-O2):
@SOL_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@errno = global i32 0
@.str = [28 x i8] c"setsockopt IP_MULTICAST_TTL\00"
define i32 @setsock_multicast_ttl(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = load i32, i32* @SOL_IP
%5 = load i32, i32* @IP_MULTICAST_TTL
%6 = call i32 @setsockopt(i32 %0, i32 %4, i32 %5, i32* %3, i32 4)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = sub nsw i32 0, %9
%11 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %8, %2
%13 = phi i32 [ %10, %8 ], [ %6, %2 ]
ret i32 %13
}