#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 */
struct dhcp_binding {
  int dummy;
};

/* Variables and functions */
int bootp_socket_create(struct dhcp_binding *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dhcp_update_state_noresp(struct dhcp_binding *);
int recv_bootp_reply(int, struct dhcp_binding *);
int send_bootp_request(int, struct dhcp_binding *);
int bootp_transaction(struct dhcp_binding *binding) {
  int attempt;
  int ret;
  int sock;
  sock = bootp_socket_create(binding);
  if (sock < 0) {
    return sock;
  }
  for (attempt = 0; attempt < 3; attempt++) {
    ret = send_bootp_request(sock, binding);
    if (ret != 0) {
      continue;
    }
    ret = recv_bootp_reply(sock, binding);
    if (ret != 0) {
      dhcp_update_state_noresp(binding);
      continue;
    }
    break;
  }
  close(sock);
  return ret;
}


x86 assembly (clang, -O0):
<bootp_transaction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <bootp_socket_create@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    117d <bootp_transaction+0x2d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <bootp_transaction+0xa4>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11e6 <bootp_transaction+0x96>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <send_bootp_request@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11ac <bootp_transaction+0x5c>
jmp    11d8 <bootp_transaction+0x88>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <recv_bootp_reply@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11d3 <bootp_transaction+0x83>
mov    -0x10(%rbp),%rdi
call   1070 <dhcp_update_state_noresp@plt>
jmp    11d8 <bootp_transaction+0x88>
jmp    11e6 <bootp_transaction+0x96>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <bootp_transaction+0x34>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bootp_transaction>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <bootp_socket_create@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11df <bootp_transaction+0x8f>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <send_bootp_request@plt>
test   %eax,%eax
jne    1186 <bootp_transaction+0x36>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <recv_bootp_reply@plt>
test   %eax,%eax
je     11d4 <bootp_transaction+0x84>
mov    %r14,%rdi
call   1070 <dhcp_update_state_noresp@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <send_bootp_request@plt>
test   %eax,%eax
jne    11aa <bootp_transaction+0x5a>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <recv_bootp_reply@plt>
test   %eax,%eax
je     11d4 <bootp_transaction+0x84>
mov    %r14,%rdi
call   1070 <dhcp_update_state_noresp@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <send_bootp_request@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11d6 <bootp_transaction+0x86>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <recv_bootp_reply@plt>
test   %eax,%eax
je     11d4 <bootp_transaction+0x84>
mov    %eax,%ebp
mov    %r14,%rdi
call   1070 <dhcp_update_state_noresp@plt>
jmp    11d6 <bootp_transaction+0x86>
xor    %ebp,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.dhcp_binding = type { i32 }
define i32 @bootp_transaction(%struct.dhcp_binding* %0) {
%2 = alloca i32
%3 = alloca %struct.dhcp_binding*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.dhcp_binding* %0, %struct.dhcp_binding** %3
%7 = load %struct.dhcp_binding*, %struct.dhcp_binding** %3
%8 = call i32 @bootp_socket_create(%struct.dhcp_binding* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %6
store i32 %12, i32* %2
br label %41
13: ; preds = %1
store i32 0, i32* %4
br label %14
14: ; preds = %34, %13
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = load i32, i32* %6
%19 = load %struct.dhcp_binding*, %struct.dhcp_binding** %3
%20 = call i32 @send_bootp_request(i32 %18, %struct.dhcp_binding* %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %34
24: ; preds = %17
%25 = load i32, i32* %6
%26 = load %struct.dhcp_binding*, %struct.dhcp_binding** %3
%27 = call i32 @recv_bootp_reply(i32 %25, %struct.dhcp_binding* %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load %struct.dhcp_binding*, %struct.dhcp_binding** %3
%32 = call i32 @dhcp_update_state_noresp(%struct.dhcp_binding* %31)
br label %34
33: ; preds = %24
br label %37
34: ; preds = %30, %23
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %14
37: ; preds = %33, %14
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* %5
store i32 %40, i32* %2
br label %41
41: ; preds = %37, %11
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
%struct.dhcp_binding = type { i32 }
define i32 @bootp_transaction(%struct.dhcp_binding* %0) {
%2 = tail call i32 @bootp_socket_create(%struct.dhcp_binding* %0)
%3 = icmp slt i32 %2, 0
br i1 %3, label %31, label %4
4: ; preds = %1
%5 = tail call i32 @send_bootp_request(i32 %2, %struct.dhcp_binding* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32 @recv_bootp_reply(i32 %2, %struct.dhcp_binding* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %28, label %10
10: ; preds = %7
%11 = tail call i32 @dhcp_update_state_noresp(%struct.dhcp_binding* %0)
br label %12
12: ; preds = %4, %10
%13 = tail call i32 @send_bootp_request(i32 %2, %struct.dhcp_binding* %0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = tail call i32 @recv_bootp_reply(i32 %2, %struct.dhcp_binding* %0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %28, label %18
18: ; preds = %15
%19 = tail call i32 @dhcp_update_state_noresp(%struct.dhcp_binding* %0)
br label %20
20: ; preds = %18, %12
%21 = tail call i32 @send_bootp_request(i32 %2, %struct.dhcp_binding* %0)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = tail call i32 @recv_bootp_reply(i32 %2, %struct.dhcp_binding* %0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = tail call i32 @dhcp_update_state_noresp(%struct.dhcp_binding* %0)
br label %28
28: ; preds = %20, %26, %23, %15, %7
%29 = phi i32 [ 0, %7 ], [ 0, %15 ], [ 0, %23 ], [ %21, %20 ], [ %24, %26 ]
%30 = tail call i32 @close(i32 %2)
br label %31
31: ; preds = %1, %28
%32 = phi i32 [ %29, %28 ], [ %2, %1 ]
ret i32 %32
}