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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getline(char **, int *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
char *get_ip_addr() {
  FILE *fp;
  char *line = NULL;
  char *rv = malloc(256 * sizeof(char));
  int len, i;
  system("configure_edison --showWiFiIP > ip_addr.txt");
  fp = NULL;
  fp = fopen("ip_addr.txt", "r");
  if (fp == NULL) {
    fprintf(stderr, "failed to open output file. exiting.\n");
    exit(1);
  }
  if (getline(&line, &len, fp) > 0) {
    strcpy(rv, line);
    for (i = 0; i < strlen(rv); i++) {
      if (rv[i] == '\n')
        rv[i] = '\0';
    }
  } else {
    fprintf(stderr, "No IP address detected. Exiting.\n");
    exit(1);
  }
  fclose(fp);
  system("rm ip_addr.txt");
  return rv;
}


x86 assembly (clang, -O0):
<get_ip_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe4b(%rip),%rdi
call   1060 <system@plt>
movq   $0x0,-0x8(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1203 <get_ip_addr+0x73>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   10a0 <getline@plt>
cmp    $0x0,%rax
jle    1287 <get_ip_addr+0xf7>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    1282 <get_ip_addr+0xf2>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    126f <get_ip_addr+0xdf>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1274 <get_ip_addr+0xe4>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1232 <get_ip_addr+0xa2>
jmp    12a6 <get_ip_addr+0x116>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdc0(%rip),%rdi
call   1060 <system@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip_addr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xe4b(%rip),%rdi
call   1060 <system@plt>
lea    0xe5f(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1252 <get_ip_addr+0xc2>
mov    %rax,%r14
mov    %rsp,%rdi
lea    0xc(%rsp),%rsi
mov    %rax,%rdx
call   10a0 <getline@plt>
test   %rax,%rax
jle    1264 <get_ip_addr+0xd4>
mov    (%rsp),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1231 <get_ip_addr+0xa1>
xor    %ebx,%ebx
jmp    1223 <get_ip_addr+0x93>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1231 <get_ip_addr+0xa1>
cmpb   $0xa,(%r15,%rbx,1)
jne    1210 <get_ip_addr+0x80>
movb   $0x0,(%r15,%rbx,1)
jmp    1210 <get_ip_addr+0x80>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe36(%rip),%rdi
call   1060 <system@plt>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
jmp    1274 <get_ip_addr+0xe4>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"configure_edison --showWiFiIP > ip_addr.txt\00"
@.str.1 = [12 x i8] c"ip_addr.txt\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [38 x i8] c"failed to open output file. exiting.\0A\00"
@.str.4 = [34 x i8] c"No IP address detected. Exiting.\0A\00"
@.str.5 = [15 x i8] c"rm ip_addr.txt\00"
define i8* @get_ip_addr() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* null, i8** %2
%6 = call i8* @malloc(i32 256)
store i8* %6, i8** %3
%7 = call i32 @system(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %1
%9 = load i32*, i32** %1
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32*, i32** %1
%17 = call i64 @getline(i8** %2, i32* %4, i32* %16)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %46
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = load i8*, i8** %2
%22 = call i32 @strcpy(i8* %20, i8* %21)
store i32 0, i32* %5
br label %23
23: ; preds = %42, %19
%24 = load i32, i32* %5
%25 = load i8*, i8** %3
%26 = call i32 @strlen(i8* %25)
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %45
28: ; preds = %23
%29 = load i8*, i8** %3
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 10
br i1 %35, label %36, label %41
36: ; preds = %28
%37 = load i8*, i8** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %36, %28
br label %42
42: ; preds = %41
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %23
45: ; preds = %23
br label %50
46: ; preds = %15
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %45
%51 = load i32*, i32** %1
%52 = call i32 @fclose(i32* %51)
%53 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%54 = load i8*, i8** %3
ret i8* %54
}

LLVM IR (-O2):
@.str = [44 x i8] c"configure_edison --showWiFiIP > ip_addr.txt\00"
@.str.1 = [12 x i8] c"ip_addr.txt\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [38 x i8] c"failed to open output file. exiting.\0A\00"
@.str.4 = [34 x i8] c"No IP address detected. Exiting.\0A\00"
@.str.5 = [15 x i8] c"rm ip_addr.txt\00"
define i8* @get_ip_addr() {
%1 = alloca i8*
%2 = alloca i32
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 @system(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i64 @getline(i8** %1, i32* %2, i32* %7)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %32
16: ; preds = %13
%17 = load i8*, i8** %1
%18 = call i32 @strcpy(i8* %4, i8* %17)
%19 = call i32 @strlen(i8* %4)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %16, %27
%22 = phi i64 [ %28, %27 ], [ 0, %16 ]
%23 = getelementptr inbounds i8, i8* %4, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %21
store i8 0, i8* %23
br label %27
27: ; preds = %21, %26
%28 = add nuw nsw i64 %22, 1
%29 = call i32 @strlen(i8* %4)
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %28, %30
br i1 %31, label %21, label %36
32: ; preds = %13
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27, %16
%37 = call i32 @fclose(i32* %7)
%38 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
ret i8* %4
}