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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getTokens(char *, char *, char **, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int getReservedAddr(char reservedMacAddr[][100], char reservedIpAddr[][100]) {
  int numReservedMac = 0, numReservedIp = 0;
  char buffer[2 * 1024];
  FILE *in;
  if (!(in = fopen("/tmp/udhcpd_resrv.conf", "r"))) {
    do {
      printf("%s, ", "error");
      printf("unable to open config file: /tmp/udhcpd_resrv.conf");
      printf("\n");
    } while (0);
    return 0;
  }
  memset(buffer, 0, 2 * 1024);
  if (fgets(buffer, 2 * 1024, in)) {
    numReservedIp = getTokens(buffer, " ", reservedIpAddr, 64);
  } else {
    return 0;
  }
  memset(buffer, 0, 2 * 1024);
  if (fgets(buffer, 2 * 1024, in)) {
    numReservedMac = getTokens(buffer, " ", reservedMacAddr, 64);
  } else {
    return 0;
  }
  if (numReservedMac != numReservedIp) {
  }
  return (numReservedMac < numReservedIp ? numReservedMac : numReservedIp);
}


x86 assembly (clang, -O0):
<getReservedAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xeaf(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x828(%rbp)
cmp    $0x0,%rax
jne    11d7 <getReservedAddr+0x87>
jmp    119a <getReservedAddr+0x4a>
lea    0xe5f(%rip),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12de <getReservedAddr+0x18e>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
lea    -0x820(%rbp),%rdi
mov    -0x828(%rbp),%rdx
mov    $0x800,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1230 <getReservedAddr+0xe0>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xde5(%rip),%rsi
mov    $0x40,%ecx
call   1060 <getTokens@plt>
mov    %eax,-0x20(%rbp)
jmp    123c <getReservedAddr+0xec>
movl   $0x0,-0x4(%rbp)
jmp    12de <getReservedAddr+0x18e>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
lea    -0x820(%rbp),%rdi
mov    -0x828(%rbp),%rdx
mov    $0x800,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1295 <getReservedAddr+0x145>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd80(%rip),%rsi
mov    $0x40,%ecx
call   1060 <getTokens@plt>
mov    %eax,-0x1c(%rbp)
jmp    12a1 <getReservedAddr+0x151>
movl   $0x0,-0x4(%rbp)
jmp    12de <getReservedAddr+0x18e>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     12b2 <getReservedAddr+0x162>
jmp    12b2 <getReservedAddr+0x162>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12cc <getReservedAddr+0x17c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x82c(%rbp)
jmp    12d5 <getReservedAddr+0x185>
mov    -0x20(%rbp),%eax
mov    %eax,-0x82c(%rbp)
mov    -0x82c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getReservedAddr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xeab(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1227 <getReservedAddr+0xc7>
mov    %rax,%rbx
mov    %rsp,%r12
xor    %ebp,%ebp
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1256 <getReservedAddr+0xf6>
lea    0xe3b(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rdx
mov    $0x40,%ecx
call   1070 <getTokens@plt>
mov    %eax,%r15d
xor    %ebp,%ebp
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1256 <getReservedAddr+0xf6>
lea    0xdf8(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
mov    $0x40,%ecx
call   1070 <getTokens@plt>
cmp    %r15d,%eax
cmovl  %eax,%r15d
mov    %r15d,%ebp
jmp    1256 <getReservedAddr+0xf6>
lea    0xdd2(%rip),%rdi
lea    0xdd0(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdc6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/tmp/udhcpd_resrv.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%s, \00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [51 x i8] c"unable to open config file: /tmp/udhcpd_resrv.conf\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [2 x i8] c" \00"
define i32 @getReservedAddr([100 x i8]* %0, [100 x i8]* %1) {
%3 = alloca i32
%4 = alloca [100 x i8]*
%5 = alloca [100 x i8]*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2048 x i8]
%9 = alloca i32*
store [100 x i8]* %0, [100 x i8]** %4
store [100 x i8]* %1, [100 x i8]** %5
store i32 0, i32* %6
store i32 0, i32* %7
%10 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %9
%11 = icmp ne i32* %10, null
br i1 %11, label %18, label %12
12: ; preds = %2
br label %13
13: ; preds = %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %13
store i32 0, i32* %3
br label %59
18: ; preds = %2
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 2048)
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%22 = load i32*, i32** %9
%23 = call i64 @fgets(i8* %21, i32 2048, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%27 = load [100 x i8]*, [100 x i8]** %5
%28 = bitcast [100 x i8]* %27 to i8**
%29 = call i32 @getTokens(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8** %28, i32 64)
store i32 %29, i32* %7
br label %31
30: ; preds = %18
store i32 0, i32* %3
br label %59
31: ; preds = %25
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%33 = call i32 @memset(i8* %32, i32 0, i32 2048)
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%35 = load i32*, i32** %9
%36 = call i64 @fgets(i8* %34, i32 2048, i32* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%40 = load [100 x i8]*, [100 x i8]** %4
%41 = bitcast [100 x i8]* %40 to i8**
%42 = call i32 @getTokens(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8** %41, i32 64)
store i32 %42, i32* %6
br label %44
43: ; preds = %31
store i32 0, i32* %3
br label %59
44: ; preds = %38
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %44
br label %49
49: ; preds = %48, %44
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = load i32, i32* %6
br label %57
55: ; preds = %49
%56 = load i32, i32* %7
br label %57
57: ; preds = %55, %53
%58 = phi i32 [ %54, %53 ], [ %56, %55 ]
store i32 %58, i32* %3
br label %59
59: ; preds = %57, %43, %30, %17
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [23 x i8] c"/tmp/udhcpd_resrv.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%s, \00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [51 x i8] c"unable to open config file: /tmp/udhcpd_resrv.conf\00"
@.str.6 = [2 x i8] c" \00"
define i32 @getReservedAddr([100 x i8]* %0, [100 x i8]* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 @putchar(i32 10)
br label %26
11: ; preds = %2
%12 = call i32 @memset(i8* %4, i32 0, i32 2048)
%13 = call i64 @fgets(i8* %4, i32 2048, i32* %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %11
%16 = bitcast [100 x i8]* %1 to i8**
%17 = call i32 @getTokens(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8** %16, i32 64)
%18 = call i32 @memset(i8* %4, i32 0, i32 2048)
%19 = call i64 @fgets(i8* %4, i32 2048, i32* %5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %15
%22 = bitcast [100 x i8]* %0 to i8**
%23 = call i32 @getTokens(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8** %22, i32 64)
%24 = icmp slt i32 %23, %17
%25 = select i1 %24, i32 %23, i32 %17
br label %26
26: ; preds = %15, %11, %21, %7
%27 = phi i32 [ %25, %21 ], [ 0, %7 ], [ 0, %11 ], [ 0, %15 ]
ret i32 %27
}