#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);
uint32_t get_option_serverid(const struct dhcpmsg *const packet, int *found) {
  uint32_t ret = 0;
  uint8_t buf[500];
  *found = 0;
  const size_t ol = get_dhcp_opt(packet, 0x36, buf, sizeof buf);
  if (ol == sizeof ret) {
    *found = 1;
    memcpy(&ret, buf, sizeof ret);
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_option_serverid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x7f0(%rbp),%rdx
mov    $0x36,%esi
mov    $0x7d0,%ecx
call   1040 <get_dhcp_opt@plt>
mov    %rax,-0x7f8(%rbp)
cmpq   $0x4,-0x7f8(%rbp)
04
jne    1192 <get_option_serverid+0x72>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
lea    -0x7f0(%rbp),%rsi
lea    -0x14(%rbp),%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_option_serverid>:
push   %rbx
sub    $0x7e0,%rsp
mov    %rsi,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,(%rsi)
lea    0x10(%rsp),%rdx
mov    $0x36,%esi
mov    $0x7d0,%ecx
call   1040 <get_dhcp_opt@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x4,%rcx
jne    1176 <get_option_serverid+0x56>
movl   $0x1,(%rbx)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    0xc(%rsp),%eax
add    $0x7e0,%rsp
pop    %rbx
ret

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

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