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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getsubopt(char **, char **, char **);
int /*<<< orphan*/ perror(char *);
char *realloc(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int parse_subopt(char *optarg, char **host, char **port, char **format) {
  int subopt;
  char *ssopt = optarg;
  char *value = NULL;
  char *tokens[] = {"host", "port", "format", NULL};
  while ((subopt = getsubopt(&ssopt, tokens, &value)) != -1) {
    switch (subopt) {
    case 0:
      if (value == NULL) {
        fprintf(stderr, "Host expected\n");
        return -1;
      }
      if ((*host = realloc(*host, strlen(value) + 1)) == NULL) {
        perror("realloc");
        exit(-1);
      }
      strcpy(*host, value);
      break;
    case 1:
      if (value == NULL) {
        fprintf(stderr, "Port expected\n");
        return -1;
      }
      if ((*port = realloc(*port, strlen(value) + 1)) == NULL) {
        perror("realloc");
        exit(-1);
      }
      strcpy(*port, value);
      break;
    case 2:
      if (value == NULL) {
        fprintf(stderr, "Format expected\n");
        return -1;
      }
      if ((*format = realloc(*format, strlen(value) + 1)) == NULL) {
        perror("realloc");
        exit(-1);
      }
      strcpy(*format, value);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_subopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2c4e(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0x2c4b(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c48(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c45(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x60(%rbp),%rsi
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rdx
call   1030 <getsubopt@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     13b7 <parse_subopt+0x247>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x64(%rbp)
test   %eax,%eax
je     1219 <parse_subopt+0xa9>
jmp    11f7 <parse_subopt+0x87>
mov    -0x64(%rbp),%eax
sub    $0x1,%eax
je     12a3 <parse_subopt+0x133>
jmp    1208 <parse_subopt+0x98>
mov    -0x64(%rbp),%eax
sub    $0x2,%eax
je     132d <parse_subopt+0x1bd>
jmp    13b2 <parse_subopt+0x242>
cmpq   $0x0,-0x40(%rbp)
jne    1245 <parse_subopt+0xd5>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13be <parse_subopt+0x24e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    128e <parse_subopt+0x11e>
lea    0xda1(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    13b2 <parse_subopt+0x242>
cmpq   $0x0,-0x40(%rbp)
jne    12cf <parse_subopt+0x15f>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13be <parse_subopt+0x24e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x78(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1318 <parse_subopt+0x1a8>
lea    0xd17(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    13b2 <parse_subopt+0x242>
cmpq   $0x0,-0x40(%rbp)
jne    1359 <parse_subopt+0x1e9>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
lea    0xcef(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13be <parse_subopt+0x24e>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    -0x28(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    13a2 <parse_subopt+0x232>
lea    0xc8d(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11c7 <parse_subopt+0x57>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_subopt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rcx,0x20(%rsp)
mov    %rdx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,0x28(%rsp)
movq   $0x0,0x8(%rsp)
movaps 0x2c5e(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0x2c42(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x28(%rsp),%r14
lea    0x30(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0xe37(%rip),%r13
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <getsubopt@plt>
add    $0x1,%eax
cmp    $0x3,%eax
ja     11d0 <parse_subopt+0x60>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     12a2 <parse_subopt+0x132>
mov    %r14,%rbp
mov    0x10(%rsp),%rbx
mov    (%rbx),%r14
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r14,%rdi
call   1070 <realloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     12dd <parse_subopt+0x16d>
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbp,%r14
jmp    11d0 <parse_subopt+0x60>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     12ab <parse_subopt+0x13b>
mov    0x18(%rsp),%rbp
jmp    126f <parse_subopt+0xff>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     12b4 <parse_subopt+0x144>
mov    0x20(%rsp),%rbp
mov    0x0(%rbp),%rbx
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rbx,%rdi
call   1070 <realloc@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     12dd <parse_subopt+0x16d>
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
jmp    11d0 <parse_subopt+0x60>
xor    %eax,%eax
jmp    12ce <parse_subopt+0x15e>
lea    0xd78(%rip),%rsi
jmp    12bb <parse_subopt+0x14b>
lea    0xd86(%rip),%rsi
jmp    12bb <parse_subopt+0x14b>
lea    0xd8c(%rip),%rsi
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4c(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"host\00"
@.str.1 = [5 x i8] c"port\00"
@.str.2 = [7 x i8] c"format\00"
@__const.parse_subopt.tokens = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.3 = [15 x i8] c"Host expected\0A\00"
@.str.4 = [8 x i8] c"realloc\00"
@.str.5 = [15 x i8] c"Port expected\0A\00"
@.str.6 = [17 x i8] c"Format expected\0A\00"
define i32 @parse_subopt(i8* %0, i8** %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [4 x i8*]
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
%14 = load i8*, i8** %6
store i8* %14, i8** %11
store i8* null, i8** %12
%15 = bitcast [4 x i8*]* %13 to i8*
br label %16
16: ; preds = %91, %4
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %13, i64 0, i64 0
%18 = call i32 @getsubopt(i8** %11, i8** %17, i8** %12)
store i32 %18, i32* %10
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %92
20: ; preds = %16
%21 = load i32, i32* %10
switch i32 %21, label %91 [
i32 0, label %22
i32 1, label %45
i32 2, label %68
]
22: ; preds = %20
%23 = load i8*, i8** %12
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
28: ; preds = %22
%29 = load i8**, i8*** %7
%30 = load i8*, i8** %29
%31 = load i8*, i8** %12
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 %32, 1
%34 = call i8* @realloc(i8* %30, i32 %33)
%35 = load i8**, i8*** %7
store i8* %34, i8** %35
%36 = icmp eq i8* %34, null
br i1 %36, label %37, label %40
37: ; preds = %28
%38 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %28
%41 = load i8**, i8*** %7
%42 = load i8*, i8** %41
%43 = load i8*, i8** %12
%44 = call i32 @strcpy(i8* %42, i8* %43)
br label %91
45: ; preds = %20
%46 = load i8*, i8** %12
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
51: ; preds = %45
%52 = load i8**, i8*** %8
%53 = load i8*, i8** %52
%54 = load i8*, i8** %12
%55 = call i32 @strlen(i8* %54)
%56 = add nsw i32 %55, 1
%57 = call i8* @realloc(i8* %53, i32 %56)
%58 = load i8**, i8*** %8
store i8* %57, i8** %58
%59 = icmp eq i8* %57, null
br i1 %59, label %60, label %63
60: ; preds = %51
%61 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @exit(i32 -1)
unreachable
63: ; preds = %51
%64 = load i8**, i8*** %8
%65 = load i8*, i8** %64
%66 = load i8*, i8** %12
%67 = call i32 @strcpy(i8* %65, i8* %66)
br label %91
68: ; preds = %20
%69 = load i8*, i8** %12
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
74: ; preds = %68
%75 = load i8**, i8*** %9
%76 = load i8*, i8** %75
%77 = load i8*, i8** %12
%78 = call i32 @strlen(i8* %77)
%79 = add nsw i32 %78, 1
%80 = call i8* @realloc(i8* %76, i32 %79)
%81 = load i8**, i8*** %9
store i8* %80, i8** %81
%82 = icmp eq i8* %80, null
br i1 %82, label %83, label %86
83: ; preds = %74
%84 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%85 = call i32 @exit(i32 -1)
unreachable
86: ; preds = %74
%87 = load i8**, i8*** %9
%88 = load i8*, i8** %87
%89 = load i8*, i8** %12
%90 = call i32 @strcpy(i8* %88, i8* %89)
br label %91
91: ; preds = %20, %86, %63, %40
br label %16
92: ; preds = %16
store i32 0, i32* %5
br label %93
93: ; preds = %92, %71, %48, %25
%94 = load i32, i32* %5
ret i32 %94
}

LLVM IR (-O2):
@.str = [5 x i8] c"host\00"
@.str.1 = [5 x i8] c"port\00"
@.str.2 = [7 x i8] c"format\00"
@__const.parse_subopt.tokens = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.3 = [15 x i8] c"Host expected\0A\00"
@.str.4 = [8 x i8] c"realloc\00"
@.str.5 = [15 x i8] c"Port expected\0A\00"
@.str.6 = [17 x i8] c"Format expected\0A\00"
define i32 @parse_subopt(i8* %0, i8** nocapture %1, i8** nocapture %2, i8** nocapture %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [4 x i8*]
%8 = bitcast i8** %5 to i8*
store i8* %0, i8** %5
%9 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%10 = bitcast [4 x i8*]* %7 to i8*
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %7, i64 0, i64 0
br label %12
12: ; preds = %14, %4
%13 = call i32 @getsubopt(i8** %5, i8** %11, i8** %6)
switch i32 %13, label %14 [
i32 -1, label %64
i32 0, label %15
i32 1, label %30
i32 2, label %45
]
14: ; preds = %12, %57, %42, %27
br label %12
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %60, label %18
18: ; preds = %15
%19 = load i8*, i8** %1
%20 = call i32 @strlen(i8* %16)
%21 = add nsw i32 %20, 1
%22 = call i8* @realloc(i8* %19, i32 %21)
store i8* %22, i8** %1
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %18
%28 = load i8*, i8** %6
%29 = call i32 @strcpy(i8* %22, i8* %28)
br label %14
30: ; preds = %12
%31 = load i8*, i8** %6
%32 = icmp eq i8* %31, null
br i1 %32, label %60, label %33
33: ; preds = %30
%34 = load i8*, i8** %2
%35 = call i32 @strlen(i8* %31)
%36 = add nsw i32 %35, 1
%37 = call i8* @realloc(i8* %34, i32 %36)
store i8* %37, i8** %2
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %33
%43 = load i8*, i8** %6
%44 = call i32 @strcpy(i8* %37, i8* %43)
br label %14
45: ; preds = %12
%46 = load i8*, i8** %6
%47 = icmp eq i8* %46, null
br i1 %47, label %60, label %48
48: ; preds = %45
%49 = load i8*, i8** %3
%50 = call i32 @strlen(i8* %46)
%51 = add nsw i32 %50, 1
%52 = call i8* @realloc(i8* %49, i32 %51)
store i8* %52, i8** %3
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @exit(i32 -1)
unreachable
57: ; preds = %48
%58 = load i8*, i8** %6
%59 = call i32 @strcpy(i8* %52, i8* %58)
br label %14
60: ; preds = %45, %30, %15
%61 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %15 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), %30 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), %45 ]
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* %61)
br label %64
64: ; preds = %12, %60
%65 = phi i32 [ -1, %60 ], [ 0, %12 ]
ret i32 %65
}