#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 cmsghdr {
  size_t cmsg_len;
};

/* Variables and functions */
size_t CMSG_ALIGN(int);
scalar_t__ CMSG_DATA(struct cmsghdr const *);
int /*<<< orphan*/ printf(char *, ...);
void print_opts(const char *name, const struct cmsghdr *c) {
  const unsigned char *opts = (const unsigned char *)CMSG_DATA(c);
  const size_t len = c->cmsg_len - CMSG_ALIGN(sizeof(*c));
  printf("%s", name);
  if (len) {
    printf(", {opts=0x");
    size_t i;
    for (i = 0; i < len; ++i)
      printf("%02x", opts[i]);
    printf("}");
  }
}


x86 assembly (clang, -O0):
<print_opts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <CMSG_DATA@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    $0x8,%edi
call   1040 <CMSG_ALIGN@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
je     11ea <print_opts+0xba>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11dc <print_opts+0xac>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a3 <print_opts+0x73>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_opts>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <CMSG_DATA@plt>
mov    %rax,%r12
mov    (%r14),%r13
mov    $0x8,%edi
call   1050 <CMSG_ALIGN@plt>
mov    %rax,%r14
lea    0xe8f(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
sub    %r14,%r13
je     11cb <print_opts+0x8b>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe79(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11a0 <print_opts+0x60>
mov    $0x7d,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.cmsghdr = type { i64 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [11 x i8] c", {opts=0x\00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [2 x i8] c"}\00"
define void @print_opts(i8* %0, %struct.cmsghdr* %1) {
%3 = alloca i8*
%4 = alloca %struct.cmsghdr*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store %struct.cmsghdr* %1, %struct.cmsghdr** %4
%8 = load %struct.cmsghdr*, %struct.cmsghdr** %4
%9 = call i64 @CMSG_DATA(%struct.cmsghdr* %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %5
%11 = load %struct.cmsghdr*, %struct.cmsghdr** %4
%12 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = call i64 @CMSG_ALIGN(i32 8)
%15 = sub i64 %13, %14
store i64 %15, i64* %6
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i64, i64* %6
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %38
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* %7
br label %22
22: ; preds = %33, %20
%23 = load i64, i64* %7
%24 = load i64, i64* %6
%25 = icmp ult i64 %23, %24
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = load i64, i64* %7
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %26
%34 = load i64, i64* %7
%35 = add i64 %34, 1
store i64 %35, i64* %7
br label %22
36: ; preds = %22
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %2
ret void
}

LLVM IR (-O2):
%struct.cmsghdr = type { i64 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [11 x i8] c", {opts=0x\00"
@.str.2 = [5 x i8] c"%02x\00"
define void @print_opts(i8* %0, %struct.cmsghdr* %1) {
%3 = tail call i64 @CMSG_DATA(%struct.cmsghdr* %1)
%4 = inttoptr i64 %3 to i8*
%5 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %1, i64 0, i32 0
%6 = load i64, i64* %5
%7 = tail call i64 @CMSG_ALIGN(i32 8)
%8 = sub i64 %6, %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = icmp eq i64 %8, 0
br i1 %10, label %23, label %11
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ %19, %13 ], [ 0, %11 ]
%15 = getelementptr inbounds i8, i8* %4, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = add nuw i64 %14, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %21, label %13
21: ; preds = %13
%22 = tail call i32 @putchar(i32 125)
br label %23
23: ; preds = %21, %2
ret void
}