#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct dhcpmsg {
  int dummy;
};

/* Variables and functions */
size_t get_dhcp_opt(struct dhcpmsg const *const, int, int /*<<< orphan*/ *,
                    int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
uint32_t get_option_leasetime(const struct dhcpmsg *const packet) {
  uint32_t ret = 0;
  uint8_t buf[500];
  const size_t ol = get_dhcp_opt(packet, 0x33, buf, sizeof buf);
  if (ol == sizeof ret) {
    memcpy(&ret, buf, sizeof ret);
    ret = ntohl(ret);
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_option_leasetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x7e0(%rbp),%rdx
mov    $0x33,%esi
mov    $0x7d0,%ecx
call   1040 <get_dhcp_opt@plt>
mov    %rax,-0x7e8(%rbp)
cmpq   $0x4,-0x7e8(%rbp)
04
jne    1195 <get_option_leasetime+0x65>
lea    -0x7e0(%rbp),%rsi
lea    -0xc(%rbp),%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0xc(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_option_leasetime>:
sub    $0x7e8,%rsp
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rdx
mov    $0x33,%esi
mov    $0x7d0,%ecx
call   1040 <get_dhcp_opt@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x4,%rcx
jne    117b <get_option_leasetime+0x4b>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    0xc(%rsp),%edi
call   1050 <ntohl@plt>
add    $0x7e8,%rsp
ret

LLVM IR (-O0):
%struct.dhcpmsg = type { i32 }
define i32 @get_option_leasetime(%struct.dhcpmsg* %0) {
%2 = alloca %struct.dhcpmsg*
%3 = alloca i32
%4 = alloca [500 x i32]
%5 = alloca i64
store %struct.dhcpmsg* %0, %struct.dhcpmsg** %2
store i32 0, i32* %3
%6 = load %struct.dhcpmsg*, %struct.dhcpmsg** %2
%7 = getelementptr inbounds [500 x i32], [500 x i32]* %4, i64 0, i64 0
%8 = call i64 @get_dhcp_opt(%struct.dhcpmsg* %6, i32 51, i32* %7, i32 2000)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = icmp eq i64 %9, 4
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = getelementptr inbounds [500 x i32], [500 x i32]* %4, i64 0, i64 0
%13 = call i32 @memcpy(i32* %3, i32* %12, i32 4)
%14 = load i32, i32* %3
%15 = call i32 @ntohl(i32 %14)
store i32 %15, i32* %3
br label %16
16: ; preds = %11, %1
%17 = load i32, i32* %3
ret i32 %17
}

LLVM IR (-O2):
%struct.dhcpmsg = type { i32 }
define i32 @get_option_leasetime(%struct.dhcpmsg* %0) {
%2 = alloca i32
%3 = alloca [500 x i32]
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast [500 x i32]* %3 to i8*
%6 = getelementptr inbounds [500 x i32], [500 x i32]* %3, i64 0, i64 0
%7 = call i64 @get_dhcp_opt(%struct.dhcpmsg* %0, i32 51, i32* %6, i32 2000)
%8 = icmp eq i64 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = call i32 @memcpy(i32* %2, i32* %6, i32 4)
%11 = load i32, i32* %2
%12 = call i32 @ntohl(i32 %11)
br label %13
13: ; preds = %9, %1
%14 = phi i32 [ %12, %9 ], [ 0, %1 ]
ret i32 %14
}