#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 */
char *getenv(char *);
int sscanf(char const *, char *, unsigned int *);
unsigned int socket_wrapper_default_iface(void) {
  const char *s = getenv("SOCKET_WRAPPER_DEFAULT_IFACE");
  if (s) {
    unsigned int iface;
    if (sscanf(s, "%u", &iface) == 1) {
      if (iface >= 1 && iface <= 16) {
        return iface;
      }
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<socket_wrapper_default_iface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1189 <socket_wrapper_default_iface+0x69>
mov    -0x10(%rbp),%rdi
lea    0xecf(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1184 <socket_wrapper_default_iface+0x64>
cmpl   $0x1,-0x14(%rbp)
jb     117f <socket_wrapper_default_iface+0x5f>
cmpl   $0x10,-0x14(%rbp)
ja     117f <socket_wrapper_default_iface+0x5f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <socket_wrapper_default_iface+0x70>
jmp    1184 <socket_wrapper_default_iface+0x64>
jmp    1189 <socket_wrapper_default_iface+0x69>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_wrapper_default_iface>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
call   1030 <getenv@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     1162 <socket_wrapper_default_iface+0x42>
lea    0xedb(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1162 <socket_wrapper_default_iface+0x42>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    $0x10,%ecx
jae    1162 <socket_wrapper_default_iface+0x42>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"SOCKET_WRAPPER_DEFAULT_IFACE\00"
@.str.1 = [3 x i8] c"%u\00"
define i32 @socket_wrapper_default_iface() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = call i8* @getenv(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %21
7: ; preds = %0
%8 = load i8*, i8** %2
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp uge i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* %3
%16 = icmp ule i32 %15, 16
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i32, i32* %3
store i32 %18, i32* %1
br label %22
19: ; preds = %14, %11
br label %20
20: ; preds = %19, %7
br label %21
21: ; preds = %20, %0
store i32 1, i32* %1
br label %22
22: ; preds = %21, %17
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [29 x i8] c"SOCKET_WRAPPER_DEFAULT_IFACE\00"
@.str.1 = [3 x i8] c"%u\00"
define i32 @socket_wrapper_default_iface() {
%1 = alloca i32
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %0
%5 = bitcast i32* %1 to i8*
%6 = call i32 @sscanf(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = load i32, i32* %1
%10 = add i32 %9, -1
%11 = icmp ult i32 %10, 16
br i1 %11, label %13, label %12
12: ; preds = %4, %8
br label %14
13: ; preds = %8
br label %14
14: ; preds = %0, %12, %13
%15 = phi i32 [ %9, %13 ], [ 1, %12 ], [ 1, %0 ]
ret i32 %15
}