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

/* Variables and functions */
int SOF_TIMESTAMPING_TX_SOFTWARE;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_TIMESTAMPING;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int setsockopt_ts(int fd, int flags) {
  int val;
  val = 0;
  if (flags & (0x100000 | 0x200000 | 0x400000)) {
    if (flags & 0x100000)
      val |= SOF_TIMESTAMPING_TX_SOFTWARE;
    if (flags & 0x400000)
      val |= (1 << 8);
    if (flags & 0x200000)
      val |= (1 << 9);
    val |= (1 << 7);
    flags &= ~(0x100000 | 0x200000 | 0x400000);
  }
  if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, (char *)&val, sizeof(val)))
    error(1, 0, "setsockopt");
  return flags;
}


x86 assembly (clang, -O0):
<setsockopt_ts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x700000,%eax
cmp    $0x0,%eax
je     11b4 <setsockopt_ts+0x94>
mov    -0x8(%rbp),%eax
and    $0x100000,%eax
cmp    $0x0,%eax
je     1166 <setsockopt_ts+0x46>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x400000,%eax
cmp    $0x0,%eax
je     1182 <setsockopt_ts+0x62>
mov    -0xc(%rbp),%eax
or     $0x100,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x200000,%eax
cmp    $0x0,%eax
je     119e <setsockopt_ts+0x7e>
mov    -0xc(%rbp),%eax
or     $0x200,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     $0x80,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff8fffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     11f5 <setsockopt_ts+0xd5>
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe10(%rip),%rdx
call   1040 <error@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setsockopt_ts>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
movl   $0x0,0xc(%rsp)
test   $0x700000,%esi
je     1172 <setsockopt_ts+0x52>
mov    %ebx,%eax
shl    $0xb,%eax
sar    $0x1f,%eax
mov    0x2e82(%rip),%rcx
and    (%rcx),%eax
mov    %ebx,%ecx
shr    $0xe,%ecx
and    $0x100,%ecx
mov    %ebx,%edx
shr    $0xc,%edx
and    $0x200,%edx
or     %ecx,%edx
or     %eax,%edx
or     $0x80,%edx
mov    %edx,0xc(%rsp)
and    $0xff8fffff,%ebx
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     11ac <setsockopt_ts+0x8c>
lea    0xe60(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <error@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SOF_TIMESTAMPING_TX_SOFTWARE = global i32 0
@SOL_SOCKET = global i32 0
@SO_TIMESTAMPING = global i32 0
@.str = [11 x i8] c"setsockopt\00"
define i32 @setsockopt_ts(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* %4
%7 = and i32 %6, 7340032
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %36
9: ; preds = %2
%10 = load i32, i32* %4
%11 = and i32 %10, 1048576
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @SOF_TIMESTAMPING_TX_SOFTWARE
%15 = load i32, i32* %5
%16 = or i32 %15, %14
store i32 %16, i32* %5
br label %17
17: ; preds = %13, %9
%18 = load i32, i32* %4
%19 = and i32 %18, 4194304
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %5
%23 = or i32 %22, 256
store i32 %23, i32* %5
br label %24
24: ; preds = %21, %17
%25 = load i32, i32* %4
%26 = and i32 %25, 2097152
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %5
%30 = or i32 %29, 512
store i32 %30, i32* %5
br label %31
31: ; preds = %28, %24
%32 = load i32, i32* %5
%33 = or i32 %32, 128
store i32 %33, i32* %5
%34 = load i32, i32* %4
%35 = and i32 %34, -7340033
store i32 %35, i32* %4
br label %36
36: ; preds = %31, %2
%37 = load i32, i32* %3
%38 = load i32, i32* @SOL_SOCKET
%39 = load i32, i32* @SO_TIMESTAMPING
%40 = bitcast i32* %5 to i8*
%41 = call i64 @setsockopt(i32 %37, i32 %38, i32 %39, i8* %40, i32 4)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %45
45: ; preds = %43, %36
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@SOF_TIMESTAMPING_TX_SOFTWARE = global i32 0
@SOL_SOCKET = global i32 0
@SO_TIMESTAMPING = global i32 0
@.str = [11 x i8] c"setsockopt\00"
define i32 @setsockopt_ts(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = and i32 %1, 7340032
%6 = icmp eq i32 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = and i32 %1, 1048576
%9 = icmp eq i32 %8, 0
%10 = load i32, i32* @SOF_TIMESTAMPING_TX_SOFTWARE
%11 = select i1 %9, i32 0, i32 %10
%12 = lshr i32 %1, 14
%13 = and i32 %12, 256
%14 = or i32 %13, %11
%15 = lshr i32 %1, 12
%16 = and i32 %15, 512
%17 = or i32 %16, %14
%18 = or i32 %17, 128
store i32 %18, i32* %3
%19 = and i32 %1, -7340033
br label %20
20: ; preds = %7, %2
%21 = phi i32 [ %19, %7 ], [ %1, %2 ]
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_TIMESTAMPING
%24 = call i64 @setsockopt(i32 %0, i32 %22, i32 %23, i8* %4, i32 4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %20
ret i32 %21
}