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

/* Variables and functions */
int IPPROTO_IP;
int IPPROTO_IPV6;
int SOL_SOCKET;
int darwin_convert_sockopt_ip_option(int);
int darwin_convert_sockopt_ipv6_option(int);
int darwin_convert_sockopt_socket_option(int);
int /*<<< orphan*/ printf(char *);
int darwin_convert_sockopt_option(int *level, int *optname) {
  if (*level == 1) {
    *level = SOL_SOCKET;
    *optname = darwin_convert_sockopt_socket_option(*optname);
  }
  if (*level == IPPROTO_IP) {
    *optname = darwin_convert_sockopt_ip_option(*optname);
  }
  if (*level == IPPROTO_IPV6) {
    *optname = darwin_convert_sockopt_ipv6_option(*optname);
  }
  if (*optname == -1) {
    printf("WARN: unknown sockopt\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<darwin_convert_sockopt_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    117f <darwin_convert_sockopt_option+0x3f>
mov    0x2e84(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <darwin_convert_sockopt_socket_option@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%eax
jne    11a7 <darwin_convert_sockopt_option+0x67>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <darwin_convert_sockopt_ip_option@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2e1c(%rip),%rcx
cmp    (%rcx),%eax
jne    11cf <darwin_convert_sockopt_option+0x8f>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1060 <darwin_convert_sockopt_ipv6_option@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    11f4 <darwin_convert_sockopt_option+0xb4>
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fb <darwin_convert_sockopt_option+0xbb>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<darwin_convert_sockopt_option>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rdi),%ecx
cmp    $0x1,%ecx
jne    1169 <darwin_convert_sockopt_option+0x29>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
mov    (%rbx),%edi
call   1050 <darwin_convert_sockopt_socket_option@plt>
mov    %eax,(%rbx)
mov    (%r14),%ecx
mov    0x2e70(%rip),%rax
cmp    (%rax),%ecx
jne    1180 <darwin_convert_sockopt_option+0x40>
mov    (%rbx),%edi
call   1040 <darwin_convert_sockopt_ip_option@plt>
mov    %eax,(%rbx)
mov    (%r14),%ecx
mov    0x2e49(%rip),%rdx
mov    (%rbx),%eax
cmp    (%rdx),%ecx
jne    1196 <darwin_convert_sockopt_option+0x56>
mov    %eax,%edi
call   1060 <darwin_convert_sockopt_ipv6_option@plt>
mov    %eax,(%rbx)
mov    $0x1,%ecx
cmp    $0xffffffff,%eax
jne    11ae <darwin_convert_sockopt_option+0x6e>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@IPPROTO_IP = global i32 0
@IPPROTO_IPV6 = global i32 0
@.str = [23 x i8] c"WARN: unknown sockopt\0A\00"
define i32 @darwin_convert_sockopt_option(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* %6
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32*, i32** %4
store i32 %10, i32* %11
%12 = load i32*, i32** %5
%13 = load i32, i32* %12
%14 = call i32 @darwin_convert_sockopt_socket_option(i32 %13)
%15 = load i32*, i32** %5
store i32 %14, i32* %15
br label %16
16: ; preds = %9, %2
%17 = load i32*, i32** %4
%18 = load i32, i32* %17
%19 = load i32, i32* @IPPROTO_IP
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32*, i32** %5
%23 = load i32, i32* %22
%24 = call i32 @darwin_convert_sockopt_ip_option(i32 %23)
%25 = load i32*, i32** %5
store i32 %24, i32* %25
br label %26
26: ; preds = %21, %16
%27 = load i32*, i32** %4
%28 = load i32, i32* %27
%29 = load i32, i32* @IPPROTO_IPV6
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = call i32 @darwin_convert_sockopt_ipv6_option(i32 %33)
%35 = load i32*, i32** %5
store i32 %34, i32* %35
br label %36
36: ; preds = %31, %26
%37 = load i32*, i32** %5
%38 = load i32, i32* %37
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %43
42: ; preds = %36
store i32 1, i32* %3
br label %43
43: ; preds = %42, %40
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@IPPROTO_IP = global i32 0
@IPPROTO_IPV6 = global i32 0
@str = [22 x i8] c"WARN: unknown sockopt\00"
define i32 @darwin_convert_sockopt_option(i32* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %0
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @SOL_SOCKET
store i32 %6, i32* %0
%7 = load i32, i32* %1
%8 = tail call i32 @darwin_convert_sockopt_socket_option(i32 %7)
store i32 %8, i32* %1
%9 = load i32, i32* %0
br label %10
10: ; preds = %5, %2
%11 = phi i32 [ %9, %5 ], [ %3, %2 ]
%12 = load i32, i32* @IPPROTO_IP
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %1
%16 = tail call i32 @darwin_convert_sockopt_ip_option(i32 %15)
store i32 %16, i32* %1
%17 = load i32, i32* %0
br label %18
18: ; preds = %14, %10
%19 = phi i32 [ %17, %14 ], [ %11, %10 ]
%20 = load i32, i32* @IPPROTO_IPV6
%21 = icmp eq i32 %19, %20
%22 = load i32, i32* %1
br i1 %21, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @darwin_convert_sockopt_ipv6_option(i32 %22)
store i32 %24, i32* %1
br label %25
25: ; preds = %18, %23
%26 = phi i32 [ %24, %23 ], [ %22, %18 ]
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %25, %28
%31 = phi i32 [ 0, %28 ], [ 1, %25 ]
ret i32 %31
}