#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 socket {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ copy_from_user(char *, char *, int);
int ax25_setsockopt(struct socket *sock, int level, int optname, char *optval,
                    int optlen) {
  char devname[16];
  int res = 0;
  if (optlen < sizeof(int))
    return -22;
  switch (optname) {
  case 25:
    if (optlen > 16)
      optlen = 16;
    if (copy_from_user(devname, optval, optlen)) {
      res = -14;
      break;
    }
  default:
    res = -92;
  }
  return res;
}


x86 assembly (clang, -O0):
<ax25_setsockopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x44(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x4,%rax
jae    114b <ax25_setsockopt+0x3b>
movl   $0xffffffea,-0x4(%rbp)
jmp    11a4 <ax25_setsockopt+0x94>
mov    -0x18(%rbp),%eax
sub    $0x19,%eax
jne    1197 <ax25_setsockopt+0x87>
jmp    115c <ax25_setsockopt+0x4c>
cmpl   $0x10,-0x24(%rbp)
jle    116d <ax25_setsockopt+0x5d>
movl   $0x10,-0x24(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <copy_from_user@plt>
cmp    $0x0,%eax
je     1192 <ax25_setsockopt+0x82>
movl   $0xfffffff2,-0x44(%rbp)
jmp    119e <ax25_setsockopt+0x8e>
jmp    1197 <ax25_setsockopt+0x87>
movl   $0xffffffa4,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ax25_setsockopt>:
mov    $0xffffffea,%eax
cmp    $0x4,%r8d
jb     114c <ax25_setsockopt+0x3c>
cmp    $0x19,%edx
jne    114d <ax25_setsockopt+0x3d>
sub    $0x18,%rsp
cmp    $0x10,%r8d
mov    $0x10,%edx
cmovl  %r8d,%edx
mov    %rsp,%rdi
mov    %rcx,%rsi
call   1030 <copy_from_user@plt>
mov    %eax,%ecx
mov    $0xfffffff2,%eax
test   %ecx,%ecx
lea    0x18(%rsp),%rsp
je     114d <ax25_setsockopt+0x3d>
ret
mov    $0xffffffa4,%eax
ret

LLVM IR (-O0):
%struct.socket = type { i32 }
define i32 @ax25_setsockopt(%struct.socket* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.socket*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [16 x i8]
%13 = alloca i32
store %struct.socket* %0, %struct.socket** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 0, i32* %13
%14 = load i32, i32* %11
%15 = sext i32 %14 to i64
%16 = icmp ult i64 %15, 4
br i1 %16, label %17, label %18
17: ; preds = %5
store i32 -22, i32* %6
br label %35
18: ; preds = %5
%19 = load i32, i32* %9
switch i32 %19, label %32 [
i32 25, label %20
]
20: ; preds = %18
%21 = load i32, i32* %11
%22 = icmp sgt i32 %21, 16
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 16, i32* %11
br label %24
24: ; preds = %23, %20
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%26 = load i8*, i8** %10
%27 = load i32, i32* %11
%28 = call i32 @copy_from_user(i8* %25, i8* %26, i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 -14, i32* %13
br label %33
31: ; preds = %24
br label %32
32: ; preds = %18, %31
store i32 -92, i32* %13
br label %33
33: ; preds = %32, %30
%34 = load i32, i32* %13
store i32 %34, i32* %6
br label %35
35: ; preds = %33, %17
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
%struct.socket = type { i32 }
define i32 @ax25_setsockopt(%struct.socket* nocapture readnone %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%8 = icmp ult i32 %4, 4
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = icmp eq i32 %2, 25
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = icmp slt i32 %4, 16
%13 = select i1 %12, i32 %4, i32 16
%14 = call i32 @copy_from_user(i8* %7, i8* %3, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11, %9
br label %17
17: ; preds = %16, %11, %5
%18 = phi i32 [ -22, %5 ], [ -92, %16 ], [ -14, %11 ]
ret i32 %18
}