#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*/ u_int32_t;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ printf(char *, char *);
int addAddress(char *ip) {
  FILE *in;
  struct in_addr inp;
  printf("adding: %s\n", ip);
  inet_aton(ip, &inp);
  in = fopen("/home/matthewr/dhcpd/dhcpd/dhcpd.iplist", "a");
  if (in == NULL)
    return -1;
  fwrite(&inp.s_addr, sizeof(u_int32_t), 1, in);
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<addAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <inet_aton@plt>
lea    0xe8c(%rip),%rdi
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <addAddress+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <addAddress+0x7e>
lea    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addAddress>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xea1(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <inet_aton@plt>
lea    0xe91(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b2 <addAddress+0x62>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11b7 <addAddress+0x67>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [12 x i8] c"adding: %s\0A\00"
@.str.1 = [40 x i8] c"/home/matthewr/dhcpd/dhcpd/dhcpd.iplist\00"
@.str.2 = [2 x i8] c"a\00"
define i32 @addAddress(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.in_addr
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %3
%9 = call i32 @inet_aton(i8* %8, %struct.in_addr* %5)
%10 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %20
14: ; preds = %1
%15 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
%16 = load i32*, i32** %4
%17 = call i32 @fwrite(i32* %15, i32 4, i32 1, i32* %16)
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
store i32 0, i32* %2
br label %20
20: ; preds = %14, %13
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [12 x i8] c"adding: %s\0A\00"
@.str.1 = [40 x i8] c"/home/matthewr/dhcpd/dhcpd/dhcpd.iplist\00"
@.str.2 = [2 x i8] c"a\00"
define i32 @addAddress(i8* %0) {
%2 = alloca %struct.in_addr
%3 = bitcast %struct.in_addr* %2 to i8*
%4 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32 @inet_aton(i8* %0, %struct.in_addr* %2)
%6 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
%10 = call i32 @fwrite(i32* %9, i32 4, i32 1, i32* %6)
%11 = call i32 @fclose(i32* %6)
br label %12
12: ; preds = %1, %8
%13 = phi i32 [ 0, %8 ], [ -1, %1 ]
ret i32 %13
}