#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int cc_iw_get_dhcp_info(char *mac, char *ip) {
  FILE *fp;
  char line[256];
  char *result = NULL;
  char delims[] = " ";
  int ret = -1;
start_:
  fp = popen("cat /tmp/dhcp.leases", "r");
  if (!fp) {
    sleep(10);
    goto start_;
  }
  while (fgets(line, 256, fp)) {
    result = strtok(line, delims);
    while (result) {
      result = strtok(NULL, delims);
      if (memcmp(result, mac, 17) == 0) {
        result = strtok(NULL, delims);
        if (result) {
          strcpy(ip, result);
          ret = 0;
          goto final;
        }
        goto final;
      }
      break;
    }
  }
final:
  pclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<cc_iw_get_dhcp_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x128(%rbp)
mov    0xe6b(%rip),%ax
mov    %ax,-0x12a(%rbp)
movl   $0xffffffff,-0x130(%rbp)
ff ff ff
lea    0xe55(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d7 <cc_iw_get_dhcp_info+0x67>
mov    $0xa,%edi
call   1090 <sleep@plt>
jmp    11a6 <cc_iw_get_dhcp_info+0x36>
jmp    11dc <cc_iw_get_dhcp_info+0x6c>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12ac <cc_iw_get_dhcp_info+0x13c>
lea    -0x120(%rbp),%rdi
lea    -0x12a(%rbp),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     12a7 <cc_iw_get_dhcp_info+0x137>
lea    -0x12a(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x11,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    12a2 <cc_iw_get_dhcp_info+0x132>
lea    -0x12a(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     129d <cc_iw_get_dhcp_info+0x12d>
mov    -0x10(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x130(%rbp)
jmp    12b1 <cc_iw_get_dhcp_info+0x141>
jmp    12b1 <cc_iw_get_dhcp_info+0x141>
jmp    12a7 <cc_iw_get_dhcp_info+0x137>
jmp    11dc <cc_iw_get_dhcp_info+0x6c>
jmp    12b1 <cc_iw_get_dhcp_info+0x141>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x130(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cc_iw_get_dhcp_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movw   $0x20,0xe(%rsp)
lea    0xe6b(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11dd <cc_iw_get_dhcp_info+0x6d>
lea    0xe50(%rip),%r12
lea    0xe5e(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1090 <sleep@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1070 <popen@plt>
test   %rax,%rax
je     11c0 <cc_iw_get_dhcp_info+0x50>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
je     1273 <cc_iw_get_dhcp_info+0x103>
lea    0x10(%rsp),%rbp
lea    0xe(%rsp),%r13
jmp    1225 <cc_iw_get_dhcp_info+0xb5>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1273 <cc_iw_get_dhcp_info+0x103>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     1210 <cc_iw_get_dhcp_info+0xa0>
xor    %edi,%edi
mov    %r13,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x11,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1210 <cc_iw_get_dhcp_info+0xa0>
lea    0xe(%rsp),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     1273 <cc_iw_get_dhcp_info+0x103>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %r12d,%r12d
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %r12d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.cc_iw_get_dhcp_info.delims = [2 x i8] c" \00"
@.str = [21 x i8] c"cat /tmp/dhcp.leases\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @cc_iw_get_dhcp_info(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca [2 x i8]
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %7
%10 = bitcast [2 x i8]* %8 to i8*
store i32 -1, i32* %9
br label %11
11: ; preds = %15, %2
%12 = call i32* @popen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @sleep(i32 10)
br label %11
17: ; preds = %11
br label %18
18: ; preds = %48, %17
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i64 @fgets(i8* %19, i32 256, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %49
23: ; preds = %18
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%26 = call i8* @strtok(i8* %24, i8* %25)
store i8* %26, i8** %7
br label %27
27: ; preds = %23
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %48
30: ; preds = %27
%31 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%32 = call i8* @strtok(i8* null, i8* %31)
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = load i8*, i8** %3
%35 = call i64 @memcmp(i8* %33, i8* %34, i32 17)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %30
%38 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%39 = call i8* @strtok(i8* null, i8* %38)
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i8*, i8** %4
%44 = load i8*, i8** %7
%45 = call i32 @strcpy(i8* %43, i8* %44)
store i32 0, i32* %9
br label %50
46: ; preds = %37
br label %50
47: ; preds = %30
br label %48
48: ; preds = %47, %27
br label %18
49: ; preds = %18
br label %50
50: ; preds = %49, %46, %42
%51 = load i32*, i32** %5
%52 = call i32 @pclose(i32* %51)
%53 = load i32, i32* %9
ret i32 %53
}

LLVM IR (-O2):
@.str = [21 x i8] c"cat /tmp/dhcp.leases\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @cc_iw_get_dhcp_info(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca i16
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast i16* %4 to i8*
store i16 32, i16* %4
%7 = tail call i32* @popen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %13, %2
%10 = phi i32* [ %7, %2 ], [ %15, %13 ]
%11 = call i64 @fgets(i8* %5, i32 256, i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %32, label %17
13: ; preds = %2, %13
%14 = tail call i32 @sleep(i32 10)
%15 = tail call i32* @popen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %13, label %9
17: ; preds = %9, %29
%18 = call i8* @strtok(i8* %5, i8* %6)
%19 = icmp eq i8* %18, null
br i1 %19, label %29, label %20
20: ; preds = %17
%21 = call i8* @strtok(i8* null, i8* %6)
%22 = call i64 @memcmp(i8* %21, i8* %0, i32 17)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = call i8* @strtok(i8* null, i8* %6)
%26 = icmp eq i8* %25, null
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = call i32 @strcpy(i8* %1, i8* %25)
br label %32
29: ; preds = %20, %17
%30 = call i64 @fgets(i8* %5, i32 256, i32* %10)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %17
32: ; preds = %29, %9, %24, %27
%33 = phi i32 [ 0, %27 ], [ -1, %24 ], [ -1, %9 ], [ -1, %29 ]
%34 = call i32 @pclose(i32* %10)
ret i32 %33
}