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

/* Variables and functions */
int WEXITSTATUS(int /*<<< orphan*/);
int /*<<< orphan*/ dhcp_client_stop(char *);
scalar_t__ executable_exists(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ system(char *);
int dhcp_client_start(char *interface) {
  dhcp_client_stop(interface);
  char command[32 + strlen(interface)];
  if (executable_exists("dhcpcd"))
    strcpy(command, "dhcpcd");
  else if (executable_exists("dhclient"))
    strcpy(command, "dhclient");
  else if (executable_exists("dhclient3"))
    strcpy(command, "dhclient3");
  else if (executable_exists("udhcpcd"))
    strcpy(command, "udhcpcd");
  else {
    puts("error: no dhcp client executable found!");
    return -1;
  }
  strcat(command, " ");
  strcat(command, interface);
  return WEXITSTATUS(system(command));
}


x86 assembly (clang, -O0):
<dhcp_client_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <dhcp_client_stop@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x20,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe49(%rip),%rdi
call   1070 <executable_exists@plt>
cmp    $0x0,%rax
je     11ef <dhcp_client_start+0x6f>
mov    -0x30(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    129e <dhcp_client_start+0x11e>
lea    0xe0a(%rip),%rdi
call   1070 <executable_exists@plt>
cmp    $0x0,%rax
je     121a <dhcp_client_start+0x9a>
mov    -0x30(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1299 <dhcp_client_start+0x119>
lea    0xde8(%rip),%rdi
call   1070 <executable_exists@plt>
cmp    $0x0,%rax
je     1245 <dhcp_client_start+0xc5>
mov    -0x30(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1294 <dhcp_client_start+0x114>
lea    0xdc7(%rip),%rdi
call   1070 <executable_exists@plt>
cmp    $0x0,%rax
je     1270 <dhcp_client_start+0xf0>
mov    -0x30(%rbp),%rdi
lea    0xdad(%rip),%rsi
call   1030 <strcpy@plt>
jmp    128f <dhcp_client_start+0x10f>
lea    0xda4(%rip),%rdi
call   1040 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    12d5 <dhcp_client_start+0x155>
jmp    1294 <dhcp_client_start+0x114>
jmp    1299 <dhcp_client_start+0x119>
jmp    129e <dhcp_client_start+0x11e>
mov    -0x30(%rbp),%rdi
lea    0xd9a(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dhcp_client_start>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1090 <dhcp_client_stop@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
add    $0x20,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe5f(%rip),%r15
mov    %r15,%rdi
call   1070 <executable_exists@plt>
test   %rax,%rax
jne    11fe <dhcp_client_start+0x7e>
lea    0xe37(%rip),%r15
mov    %r15,%rdi
call   1070 <executable_exists@plt>
test   %rax,%rax
jne    11fe <dhcp_client_start+0x7e>
lea    0xe2c(%rip),%r15
mov    %r15,%rdi
call   1070 <executable_exists@plt>
test   %rax,%rax
jne    11fe <dhcp_client_start+0x7e>
lea    0xe22(%rip),%r15
mov    %r15,%rdi
call   1070 <executable_exists@plt>
test   %rax,%rax
je     123d <dhcp_client_start+0xbd>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xe33(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
mov    %eax,%edi
call   1080 <WEXITSTATUS@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd7(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    1232 <dhcp_client_start+0xb2>

LLVM IR (-O0):
@.str = [7 x i8] c"dhcpcd\00"
@.str.1 = [9 x i8] c"dhclient\00"
@.str.2 = [10 x i8] c"dhclient3\00"
@.str.3 = [8 x i8] c"udhcpcd\00"
@.str.4 = [40 x i8] c"error: no dhcp client executable found!\00"
@.str.5 = [2 x i8] c" \00"
define i32 @dhcp_client_start(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @dhcp_client_stop(i8* %7)
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 32, %10
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
%15 = call i64 @executable_exists(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %39
19: ; preds = %1
%20 = call i64 @executable_exists(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %38
24: ; preds = %19
%25 = call i64 @executable_exists(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %37
29: ; preds = %24
%30 = call i64 @executable_exists(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %36
34: ; preds = %29
%35 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
store i32 1, i32* %6
br label %45
36: ; preds = %32
br label %37
37: ; preds = %36, %27
br label %38
38: ; preds = %37, %22
br label %39
39: ; preds = %38, %17
%40 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%41 = load i8*, i8** %3
%42 = call i32 @strcat(i8* %14, i8* %41)
%43 = call i32 @system(i8* %14)
%44 = call i32 @WEXITSTATUS(i32 %43)
store i32 %44, i32* %2
store i32 1, i32* %6
br label %45
45: ; preds = %39, %34
%46 = load i8*, i8** %4
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
@.str = [7 x i8] c"dhcpcd\00"
@.str.1 = [9 x i8] c"dhclient\00"
@.str.2 = [10 x i8] c"dhclient3\00"
@.str.3 = [8 x i8] c"udhcpcd\00"
@.str.4 = [40 x i8] c"error: no dhcp client executable found!\00"
@.str.5 = [2 x i8] c" \00"
define i32 @dhcp_client_start(i8* %0) {
%2 = tail call i32 @dhcp_client_stop(i8* %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 32
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = tail call i64 @executable_exists(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = tail call i64 @executable_exists(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = tail call i64 @executable_exists(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = tail call i64 @executable_exists(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %27
20: ; preds = %15, %12, %9, %1
%21 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %12 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %15 ]
%22 = call i32 @strcpy(i8* %6, i8* %21)
%23 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @strcat(i8* %6, i8* %0)
%25 = call i32 @system(i8* %6)
%26 = call i32 @WEXITSTATUS(i32 %25)
br label %27
27: ; preds = %20, %18
%28 = phi i32 [ %26, %20 ], [ -1, %18 ]
ret i32 %28
}