#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ system(char *);
getIP(int tipo, char *IP) {
  FILE *tmpIP;
  char dIP[20];
  char dIP2[20];
  int i, j;
  switch (tipo) {
  case 0:
    system("ifconfig lo | grep inet > tmp");
    break;
  case 1:
    system("ifconfig wlan | grep inet > tmp");
    break;
  case 2:
    system("ifconfig eth | grep inet > tmp");
    break;
  }
  j = 0;
  tmpIP = fopen("tmp", "r");
  fscanf(tmpIP, "%s %s", dIP, dIP);
  for (i = 5; i < 20; i++) {
    IP[j] = dIP[i];
    j++;
  }
}


x86 assembly (clang, -O0):
<getIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x5c(%rbp)
test   %eax,%eax
je     1174 <getIP+0x44>
jmp    1152 <getIP+0x22>
mov    -0x5c(%rbp),%eax
sub    $0x1,%eax
je     1185 <getIP+0x55>
jmp    1163 <getIP+0x33>
mov    -0x5c(%rbp),%eax
sub    $0x2,%eax
je     1196 <getIP+0x66>
jmp    11a2 <getIP+0x72>
lea    0xe85(%rip),%rdi
call   1030 <system@plt>
jmp    11a2 <getIP+0x72>
lea    0xe92(%rip),%rdi
call   1030 <system@plt>
jmp    11a2 <getIP+0x72>
lea    0xea1(%rip),%rdi
call   1030 <system@plt>
movl   $0x0,-0x58(%rbp)
lea    0xea9(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    0xe8c(%rip),%rsi
call   1040 <fscanf@plt>
movl   $0x5,-0x54(%rbp)
cmpl   $0x14,-0x54(%rbp)
jge    1213 <getIP+0xe3>
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11df <getIP+0xaf>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIP>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
ja     1153 <getIP+0x23>
movslq %edi,%rax
lea    0xf21(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1030 <system@plt>
lea    0xeff(%rip),%rdi
lea    0xefc(%rip),%rsi
call   1050 <fopen@plt>
lea    0xef2(%rip),%rsi
mov    %rsp,%rcx
mov    %rax,%rdi
mov    %rcx,%rdx
call   1040 <fscanf@plt>
mov    0x5(%rsp),%rax
mov    0xc(%rsp),%rcx
mov    %rax,(%rbx)
mov    %rcx,0x7(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"ifconfig lo | grep inet > tmp\00"
@.str.1 = [32 x i8] c"ifconfig wlan | grep inet > tmp\00"
@.str.2 = [31 x i8] c"ifconfig eth | grep inet > tmp\00"
@.str.3 = [4 x i8] c"tmp\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [6 x i8] c"%s %s\00"
define i32 @getIP(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [20 x i8]
%8 = alloca [20 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%11 = load i32, i32* %4
switch i32 %11, label %18 [
i32 0, label %12
i32 1, label %14
i32 2, label %16
]
12: ; preds = %2
%13 = call i32 @system(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %18
14: ; preds = %2
%15 = call i32 @system(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %18
16: ; preds = %2
%17 = call i32 @system(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %2, %16, %14, %12
store i32 0, i32* %10
%19 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%23 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %21, i8* %22)
store i32 5, i32* %9
br label %24
24: ; preds = %38, %18
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 20
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %5
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %38
38: ; preds = %27
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %24
41: ; preds = %24
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [30 x i8] c"ifconfig lo | grep inet > tmp\00"
@.str.1 = [32 x i8] c"ifconfig wlan | grep inet > tmp\00"
@.str.2 = [31 x i8] c"ifconfig eth | grep inet > tmp\00"
@.str.3 = [4 x i8] c"tmp\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [6 x i8] c"%s %s\00"
@reltable.getIP = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([30 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.getIP to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.getIP to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.getIP to i64)) to i32)]
define i32 @getIP(i32 %0, i8* nocapture writeonly %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = icmp ult i32 %0, 3
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = sext i32 %0 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.getIP to i8*), i64 %8)
%10 = tail call i32 @system(i8* %9)
br label %11
11: ; preds = %2, %6
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %4, i8* %4)
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 5
ret i32 undef
}