#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 */
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ ipline;

/* Variables and functions */
int EPIPE;
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ validate_ip_str(char *, int /*<<< orphan*/ *);
int __attribute__((warn_unused_result))
get_ap_ip(uint32_t *addr_out, char *ipstr_out) {
  char ipline[80], *s;
  while (true) {
    puts("Enter an IP address for your ap [192.168.45.1]:");
    s = fgets(ipline, sizeof(ipline), stdin);
    if (s == NULL)
      return EPIPE;
    if ((strcmp((ipline), ("\n")) == 0))
      strcpy(ipline, "192.168.45.1");
    if (validate_ip_str(ipline, addr_out) == 0)
      break;
  }
  strcpy(ipstr_out, ipline);
  return 0;
}


x86 assembly (clang, -O0):
<get_ap_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1050 <fgets@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11a6 <get_ap_ip+0x56>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1205 <get_ap_ip+0xb5>
lea    -0x70(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d0 <get_ap_ip+0x80>
lea    -0x70(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <validate_ip_str@plt>
cmp    $0x0,%rax
jne    11ec <get_ap_ip+0x9c>
jmp    11f1 <get_ap_ip+0xa1>
jmp    1163 <get_ap_ip+0x13>
mov    -0x18(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ap_ip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%r12
lea    0xe93(%rip),%r15
mov    0x2e74(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xeb0(%rip),%r13
lea    0xeab(%rip),%rbp
jmp    11a0 <get_ap_ip+0x50>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <validate_ip_str@plt>
test   %rax,%rax
je     11da <get_ap_ip+0x8a>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11ed <get_ap_ip+0x9d>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1190 <get_ap_ip+0x40>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
jmp    1190 <get_ap_ip+0x40>
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
jmp    11f6 <get_ap_ip+0xa6>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Enter an IP address for your ap [192.168.45.1]:\00"
@stdin = global i32 0
@EPIPE = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [13 x i8] c"192.168.45.1\00"
define i32 @get_ap_ip(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [80 x i8]
%7 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
br label %8
8: ; preds = %2, %30
%9 = call i32 @puts(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i8* @fgets(i8* %10, i32 80, i32 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = load i32, i32* @EPIPE
store i32 %16, i32* %3
br label %35
17: ; preds = %8
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %21, %17
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%26 = load i32*, i32** %4
%27 = call i64 @validate_ip_str(i8* %25, i32* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
br label %31
30: ; preds = %24
br label %8
31: ; preds = %29
%32 = load i8*, i8** %5
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%34 = call i32 @strcpy(i8* %32, i8* %33)
store i32 0, i32* %3
br label %35
35: ; preds = %31, %15
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [48 x i8] c"Enter an IP address for your ap [192.168.45.1]:\00"
@stdin = global i32 0
@EPIPE = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [13 x i8] c"192.168.45.1\00"
define i32 @get_ap_ip(i32* %0, i8* %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %17, %2
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i8* @fgets(i8* %4, i32 80, i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = load i32, i32* @EPIPE
br label %22
12: ; preds = %5
%13 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = call i64 @validate_ip_str(i8* %4, i32* %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %5
20: ; preds = %17
%21 = call i32 @strcpy(i8* %1, i8* %4)
br label %22
22: ; preds = %20, %10
%23 = phi i32 [ %11, %10 ], [ 0, %20 ]
ret i32 %23
}