#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *strstr(char *, char *);
char *strtok(char *, char *);
int main() {
  FILE *fp;
  char returnData[128];
  char *seperateString;
  fp = popen("/sbin/ifconfig eth0", "r");
  int foundIp = 0;
  while (fgets(returnData, 128, fp) != NULL) {
    if (strstr(returnData, "inet addr") != NULL) {
      foundIp = 1;
      char *tokenReturnData = returnData;
      seperateString = strtok(tokenReturnData, ":");
      int counterToGetIP = 0;
      while (seperateString) {
        if (counterToGetIP == 1) {
          printf("Your IP address: %s\n", seperateString);
          break;
        }
        seperateString = strtok(NULL, " ");
        counterToGetIP++;
      }
      break;
    }
  }
  if (!foundIp) {
    printf("Port eth0 is down.\n");
  }
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x9c(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1275 <main+0x115>
lea    -0x90(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1270 <main+0x110>
movl   $0x1,-0x9c(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x98(%rbp)
movl   $0x0,-0xac(%rbp)
cmpq   $0x0,-0x98(%rbp)
je     126b <main+0x10b>
cmpl   $0x1,-0xac(%rbp)
jne    1240 <main+0xe0>
mov    -0x98(%rbp),%rsi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126b <main+0x10b>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdea(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x98(%rbp)
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    120b <main+0xab>
jmp    1275 <main+0x115>
jmp    1193 <main+0x33>
cmpl   $0x0,-0x9c(%rbp)
jne    1290 <main+0x130>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xe7d(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%r14
mov    %rsp,%rbx
lea    0xe78(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11ff <main+0x8f>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11a0 <main+0x30>
lea    0xe52(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     120b <main+0x9b>
lea    0xe55(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     120b <main+0x9b>
lea    0xe2d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    120b <main+0x9b>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/sbin/ifconfig eth0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"inet addr\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [21 x i8] c"Your IP address: %s\0A\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [20 x i8] c"Port eth0 is down.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [128 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32* @popen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
store i32 0, i32* %5
br label %9
9: ; preds = %36, %0
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i32* @fgets(i8* %10, i32 128, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %37
14: ; preds = %9
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%16 = call i32* @strstr(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %36
18: ; preds = %14
store i32 1, i32* %5
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = call i8* @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %21, i8** %4
store i32 0, i32* %7
br label %22
22: ; preds = %31, %18
%23 = load i8*, i8** %4
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %29)
br label %35
31: ; preds = %25
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %32, i8** %4
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %22
35: ; preds = %28, %22
br label %37
36: ; preds = %14
br label %9
37: ; preds = %35, %9
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = load i32*, i32** %2
%44 = call i32 @pclose(i32* %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"/sbin/ifconfig eth0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"inet addr\00"
@.str.3 = [2 x i8] c":\00"
@.str.4 = [21 x i8] c"Your IP address: %s\0A\00"
@.str.5 = [2 x i8] c" \00"
@str = [19 x i8] c"Port eth0 is down.\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %7, %0
%5 = call i32* @fgets(i8* %2, i32 128, i32* %3)
%6 = icmp eq i32* %5, null
br i1 %6, label %18, label %7
7: ; preds = %4
%8 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %4, label %10
10: ; preds = %7
%11 = call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %20
18: ; preds = %4
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %13, %10, %16, %18
%21 = call i32 @pclose(i32* %3)
ret i32 0
}