#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 */
unsigned long INT_MAX;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
unsigned long strtoul(char *, char **, int);
int parse_dns_retries(void) {
  unsigned long ret;
  char *retries = getenv("WG_ENDPOINT_RESOLUTION_RETRIES"), *end;
  if (!retries)
    return 15;
  if (!strcmp(retries, "infinity"))
    return -1;
  ret = strtoul(retries, &end, 10);
  if (*end || ret > INT_MAX) {
    fprintf(stderr, "Unable to parse WG_ENDPOINT_RESOLUTION_RETRIES: `%s'\n",
            retries);
    exit(1);
  }
  return (int)ret;
}


x86 assembly (clang, -O0):
<parse_dns_retries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <parse_dns_retries+0x2f>
movl   $0xf,-0x4(%rbp)
jmp    1208 <parse_dns_retries+0xb8>
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a4 <parse_dns_retries+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1208 <parse_dns_retries+0xb8>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11de <parse_dns_retries+0x8e>
mov    -0x10(%rbp),%rax
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%rax
jbe    1201 <parse_dns_retries+0xb1>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_dns_retries>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c6 <parse_dns_retries+0x76>
mov    %rax,%rbx
lea    0xeaf(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11cd <parse_dns_retries+0x7d>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    11a4 <parse_dns_retries+0x54>
mov    0x2e49(%rip),%rcx
cmp    (%rcx),%rax
jbe    11d2 <parse_dns_retries+0x82>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0xf,%eax
jmp    11d2 <parse_dns_retries+0x82>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"WG_ENDPOINT_RESOLUTION_RETRIES\00"
@.str.1 = [9 x i8] c"infinity\00"
@INT_MAX = global i64 0
@stderr = global i32 0
@.str.2 = [54 x i8] c"Unable to parse WG_ENDPOINT_RESOLUTION_RETRIES: `%s'\0A\00"
define i32 @parse_dns_retries() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = call i8* @getenv(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store i32 15, i32* %1
br label %33
9: ; preds = %0
%10 = load i8*, i8** %3
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9
store i32 -1, i32* %1
br label %33
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i64 @strtoul(i8* %15, i8** %4, i32 10)
store i64 %16, i64* %2
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %14
%22 = load i64, i64* %2
%23 = load i64, i64* @INT_MAX
%24 = icmp ugt i64 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %21, %14
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %3
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load i64, i64* %2
%32 = trunc i64 %31 to i32
store i32 %32, i32* %1
br label %33
33: ; preds = %30, %13, %8
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [31 x i8] c"WG_ENDPOINT_RESOLUTION_RETRIES\00"
@.str.1 = [9 x i8] c"infinity\00"
@INT_MAX = global i64 0
@stderr = global i32 0
@.str.2 = [54 x i8] c"Unable to parse WG_ENDPOINT_RESOLUTION_RETRIES: `%s'\0A\00"
define i32 @parse_dns_retries() {
%1 = alloca i8*
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%3 = bitcast i8** %1 to i8*
%4 = icmp eq i8* %2, null
br i1 %4, label %22, label %5
5: ; preds = %0
%6 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %5
%9 = call i64 @strtoul(i8* %2, i8** %1, i32 10)
%10 = load i8*, i8** %1
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
%13 = load i64, i64* @INT_MAX
%14 = icmp ugt i64 %9, %13
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %8
%21 = trunc i64 %9 to i32
br label %22
22: ; preds = %5, %0, %20
%23 = phi i32 [ %21, %20 ], [ 15, %0 ], [ -1, %5 ]
ret i32 %23
}