#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 */
int INET_ADDRSTRLEN;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ find_ip(char *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int getopt(int, char *const *, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char *const *argv) {
  FILE *ipdestfile = NULL;
  int writeip = 0, opt = 0;
  char addressBuffer[INET_ADDRSTRLEN];
  bzero(addressBuffer, INET_ADDRSTRLEN);
  while (!strncmp(addressBuffer, "", 1))
    find_ip(addressBuffer);
  while ((opt = getopt(argc, argv, "w:")) != -1) {
    switch (opt) {
    case 'w':
      writeip = 1;
      ipdestfile = fopen(optarg, "w");
      break;
    default:
      exit(1);
      break;
    }
  }
  if (writeip) {
    fprintf(ipdestfile, "MYIP=%s\n", addressBuffer);
    fclose(ipdestfile);
  } else {
    printf("%s\n", addressBuffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
call   1090 <bzero@plt>
mov    -0x38(%rbp),%rdi
lea    0xe0c(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1220 <main+0x90>
jmp    122e <main+0x9e>
mov    -0x38(%rbp),%rdi
call   1070 <find_ip@plt>
jmp    11f6 <main+0x66>
jmp    1233 <main+0xa3>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdbf(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     1297 <main+0x107>
mov    -0x20(%rbp),%eax
sub    $0x77,%eax
jne    1288 <main+0xf8>
jmp    1263 <main+0xd3>
movl   $0x1,-0x1c(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    1292 <main+0x102>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1233 <main+0xa3>
cmpl   $0x0,-0x1c(%rbp)
je     12c3 <main+0x133>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rdi
lea    0xd55(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12d3 <main+0x143>
mov    -0x38(%rbp),%rsi
lea    0xd3c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r12d
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1090 <bzero@plt>
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    120c <main+0x7c>
lea    0xe25(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <find_ip@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11f0 <main+0x60>
mov    %rbx,-0x30(%rbp)
mov    $0x1,%r13b
xor    %ebx,%ebx
lea    0xde7(%rip),%r14
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %r15,%rsi
lea    0xdd3(%rip),%rdx
call   10a0 <getopt@plt>
cmp    $0x77,%eax
jne    1250 <main+0xc0>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
xor    %r13d,%r13d
jmp    1220 <main+0x90>
cmp    $0xffffffff,%eax
jne    1298 <main+0x108>
test   $0x1,%r13b
mov    -0x30(%rbp),%rdx
je     1270 <main+0xe0>
lea    0xda4(%rip),%rdi
mov    %rdx,%rsi
call   1050 <printf@plt>
jmp    1287 <main+0xf7>
lea    0xd8e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@INET_ADDRSTRLEN = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"w:\00"
@optarg = global i32 0
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"MYIP=%s\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %7
store i32 0, i32* %8
%11 = load i32, i32* @INET_ADDRSTRLEN
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = load i32, i32* @INET_ADDRSTRLEN
%16 = call i32 @bzero(i8* %14, i32 %15)
br label %17
17: ; preds = %21, %2
%18 = call i32 @strncmp(i8* %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @find_ip(i8* %14)
br label %17
23: ; preds = %17
br label %24
24: ; preds = %36, %23
%25 = load i32, i32* %4
%26 = load i8**, i8*** %5
%27 = call i32 @getopt(i32 %25, i8** %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %27, i32* %8
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = load i32, i32* %8
switch i32 %30, label %34 [
i32 119, label %31
]
31: ; preds = %29
store i32 1, i32* %7
%32 = load i32, i32* @optarg
%33 = call i32* @fopen(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %6
br label %36
34: ; preds = %29
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %31
br label %24
37: ; preds = %24
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i32*, i32** %6
%42 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
br label %47
45: ; preds = %37
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %47
47: ; preds = %45, %40
store i32 0, i32* %3
%48 = load i8*, i8** %9
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@INET_ADDRSTRLEN = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"w:\00"
@optarg = global i32 0
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"MYIP=%s\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @INET_ADDRSTRLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @bzero(i8* %5, i32 %3)
%7 = call i32 @strncmp(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2, %9
%10 = call i32 @find_ip(i8* %5)
%11 = call i32 @strncmp(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %9, label %13
13: ; preds = %9, %2
br label %14
14: ; preds = %13, %18
%15 = phi i1 [ false, %18 ], [ true, %13 ]
%16 = phi i32* [ %20, %18 ], [ null, %13 ]
%17 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %17, label %21 [
i32 -1, label %23
i32 119, label %18
]
18: ; preds = %14
%19 = load i32, i32* @optarg
%20 = call i32* @fopen(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %14
21: ; preds = %14
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
br i1 %15, label %27, label %24
24: ; preds = %23
%25 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%26 = call i32 @fclose(i32* %16)
br label %29
27: ; preds = %23
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %5)
br label %29
29: ; preds = %27, %24
ret i32 0
}