#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 */
scalar_t__ bootp(char *);
scalar_t__ check_ethif();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ tftp(char *);
int get_remote_kernel(const char *kname) {
  char image_name[256];
  if (check_ethif() < 0) {
    printf("No Ethernet interface found -- no remote boot possible.\n");
    return (-1);
  }
  if (kname)
    strcpy(image_name, kname);
  else
    *image_name = 0;
  if (bootp(image_name) < 0)
    return (-1);
  if (tftp(image_name) < 0)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<get_remote_kernel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <check_ethif@plt>
cmp    $0x0,%rax
jge    1188 <get_remote_kernel+0x38>
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fa <get_remote_kernel+0xaa>
cmpq   $0x0,-0x10(%rbp)
je     11a8 <get_remote_kernel+0x58>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11af <get_remote_kernel+0x5f>
movb   $0x0,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
call   1060 <bootp@plt>
cmp    $0x0,%rax
jge    11d1 <get_remote_kernel+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fa <get_remote_kernel+0xaa>
lea    -0x110(%rbp),%rdi
call   1070 <tftp@plt>
cmp    $0x0,%rax
jge    11f3 <get_remote_kernel+0xa3>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fa <get_remote_kernel+0xaa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_remote_kernel>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <check_ethif@plt>
test   %rax,%rax
js     1179 <get_remote_kernel+0x29>
test   %rbx,%rbx
je     1187 <get_remote_kernel+0x37>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    118b <get_remote_kernel+0x3b>
lea    0xe80(%rip),%rdi
call   1050 <puts@plt>
jmp    11a6 <get_remote_kernel+0x56>
movb   $0x0,(%rsp)
mov    %rsp,%rdi
call   1060 <bootp@plt>
test   %rax,%rax
js     11a6 <get_remote_kernel+0x56>
mov    %rsp,%rdi
call   1070 <tftp@plt>
sar    $0x3f,%rax
jmp    11ab <get_remote_kernel+0x5b>
mov    $0xffffffff,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [57 x i8] c"No Ethernet interface found -- no remote boot possible.\0A\00"
define i32 @get_remote_kernel(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
store i8* %0, i8** %3
%5 = call i64 (...) @check_ethif()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %29
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %13, i8* %14)
br label %18
16: ; preds = %9
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8 0, i8* %17
br label %18
18: ; preds = %16, %12
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%20 = call i64 @bootp(i8* %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 -1, i32* %2
br label %29
23: ; preds = %18
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = call i64 @tftp(i8* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %2
br label %29
28: ; preds = %23
store i32 0, i32* %2
br label %29
29: ; preds = %28, %27, %22, %7
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@str = [56 x i8] c"No Ethernet interface found -- no remote boot possible.\00"
define i32 @get_remote_kernel(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i64 (...) @check_ethif()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %20
8: ; preds = %1
%9 = icmp eq i8* %0, null
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = call i32 @strcpy(i8* %3, i8* %0)
br label %13
12: ; preds = %8
store i8 0, i8* %3
br label %13
13: ; preds = %12, %10
%14 = call i64 @bootp(i8* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = call i64 @tftp(i8* %3)
%18 = ashr i64 %17, 63
%19 = trunc i64 %18 to i32
br label %20
20: ; preds = %16, %13, %6
%21 = phi i32 [ -1, %6 ], [ -1, %13 ], [ %19, %16 ]
ret i32 %21
}