#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 */
char *calloc(int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *inet_convert(char *inbound, int dflag) {
  int i;
  extern int vflag;
  char *outbound;
  char *scratch;
  outbound = calloc(1024, sizeof(char));
  scratch = calloc(1024, sizeof(char));
  for (i = 0; i < strlen(inbound); i++) {
    if (inbound[i] == ' ' || inbound[i] == '+')
      sprintf(scratch, "%c", '+');
    else if (inbound[i] == '&' || inbound[i] == '=')
      sprintf(scratch, "%c", inbound[i]);
    else if ((inbound[i] >= 65 && inbound[i] <= 90) ||
             (inbound[i] >= 97 && inbound[i] <= 122))
      sprintf(scratch, "%c", inbound[i]);
    else {
      if (dflag == 0)
        sprintf(scratch, "%c", inbound[i]);
      if (dflag == 1)
        sprintf(scratch, "%%%x", inbound[i]);
    }
    strcat(outbound, scratch);
  }
  if (vflag)
    printf("(verbose) post-converted string: \"%s\"\n", outbound);
  return (outbound);
}


x86 assembly (clang, -O0):
<inet_convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x400,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x400,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    1322 <inet_convert+0x1d2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     11d2 <inet_convert+0x82>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2b,%eax
jne    11ec <inet_convert+0x9c>
mov    -0x20(%rbp),%rdi
lea    0xe23(%rip),%rsi
mov    $0x2b,%edx
call   1070 <sprintf@plt>
jmp    1307 <inet_convert+0x1b7>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x26,%eax
je     1216 <inet_convert+0xc6>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1237 <inet_convert+0xe7>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xdd7(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1070 <sprintf@plt>
jmp    1302 <inet_convert+0x1b2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x41,%eax
jl     1261 <inet_convert+0x111>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5a,%eax
jle    128b <inet_convert+0x13b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x61,%eax
jl     12ac <inet_convert+0x15c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7a,%eax
jg     12ac <inet_convert+0x15c>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xd62(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1070 <sprintf@plt>
jmp    12fd <inet_convert+0x1ad>
cmpl   $0x0,-0xc(%rbp)
jne    12d2 <inet_convert+0x182>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xd37(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1070 <sprintf@plt>
cmpl   $0x1,-0xc(%rbp)
jne    12f8 <inet_convert+0x1a8>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xd14(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1070 <sprintf@plt>
jmp    12fd <inet_convert+0x1ad>
jmp    1302 <inet_convert+0x1b2>
jmp    1307 <inet_convert+0x1b7>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118c <inet_convert+0x3c>
mov    0x2cbf(%rip),%rax
cmpl   $0x0,(%rax)
je     1342 <inet_convert+0x1f2>
mov    -0x18(%rbp),%rsi
lea    0xccb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_convert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r13
mov    $0x400,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
mov    $0x400,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    121e <inet_convert+0xce>
xor    %ebp,%ebp
lea    0xe62(%rip),%r12
jmp    11c4 <inet_convert+0x74>
mov    %al,(%rbx)
movb   $0x0,0x1(%rbx)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbp
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    121e <inet_convert+0xce>
movzbl 0x0(%r13,%rbp,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x1d,%cl
ja     11f0 <inet_convert+0xa0>
movzbl %cl,%ecx
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
movw   $0x2b,(%rbx)
jmp    11a6 <inet_convert+0x56>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%ecx
and    $0xdf,%cl
add    $0xbf,%cl
cmp    $0x19,%cl
jbe    11a0 <inet_convert+0x50>
cmp    $0x1,%r14d
je     120a <inet_convert+0xba>
test   %r14d,%r14d
je     11a0 <inet_convert+0x50>
jmp    11a6 <inet_convert+0x56>
movsbl %al,%edx
mov    %rbx,%rdi
lea    0xe61(%rip),%rsi
call   1070 <sprintf@plt>
jmp    11a6 <inet_convert+0x56>
mov    0x2dc3(%rip),%rax
cmpl   $0x0,(%rax)
je     1239 <inet_convert+0xe9>
lea    0xe4c(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [5 x i8] c"%%%x\00"
@vflag = external global i32
@.str.2 = [39 x i8] c"(verbose) post-converted string: \22%s\22\0A\00"
define i8* @inet_convert(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i8* @calloc(i32 1024, i32 1)
store i8* %8, i8** %6
%9 = call i8* @calloc(i32 1024, i32 1)
store i8* %9, i8** %7
store i32 0, i32* %5
br label %10
10: ; preds = %127, %2
%11 = load i32, i32* %5
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %130
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 32
br i1 %22, label %31, label %23
23: ; preds = %15
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 43
br i1 %30, label %31, label %34
31: ; preds = %23, %15
%32 = load i8*, i8** %7
%33 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext 43)
br label %123
34: ; preds = %23
%35 = load i8*, i8** %3
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 38
br i1 %41, label %50, label %42
42: ; preds = %34
%43 = load i8*, i8** %3
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 61
br i1 %49, label %50, label %58
50: ; preds = %42, %34
%51 = load i8*, i8** %7
%52 = load i8*, i8** %3
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %56)
br label %122
58: ; preds = %42
%59 = load i8*, i8** %3
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp sge i32 %64, 65
br i1 %65, label %66, label %74
66: ; preds = %58
%67 = load i8*, i8** %3
%68 = load i32, i32* %5
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp sle i32 %72, 90
br i1 %73, label %90, label %74
74: ; preds = %66, %58
%75 = load i8*, i8** %3
%76 = load i32, i32* %5
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp sge i32 %80, 97
br i1 %81, label %82, label %98
82: ; preds = %74
%83 = load i8*, i8** %3
%84 = load i32, i32* %5
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp sle i32 %88, 122
br i1 %89, label %90, label %98
90: ; preds = %82, %66
%91 = load i8*, i8** %7
%92 = load i8*, i8** %3
%93 = load i32, i32* %5
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
%96 = load i8, i8* %95
%97 = call i32 @sprintf(i8* %91, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %96)
br label %121
98: ; preds = %82, %74
%99 = load i32, i32* %4
%100 = icmp eq i32 %99, 0
br i1 %100, label %101, label %109
101: ; preds = %98
%102 = load i8*, i8** %7
%103 = load i8*, i8** %3
%104 = load i32, i32* %5
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8, i8* %103, i64 %105
%107 = load i8, i8* %106
%108 = call i32 @sprintf(i8* %102, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %107)
br label %109
109: ; preds = %101, %98
%110 = load i32, i32* %4
%111 = icmp eq i32 %110, 1
br i1 %111, label %112, label %120
112: ; preds = %109
%113 = load i8*, i8** %7
%114 = load i8*, i8** %3
%115 = load i32, i32* %5
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i8, i8* %114, i64 %116
%118 = load i8, i8* %117
%119 = call i32 @sprintf(i8* %113, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 signext %118)
br label %120
120: ; preds = %112, %109
br label %121
121: ; preds = %120, %90
br label %122
122: ; preds = %121, %50
br label %123
123: ; preds = %122, %31
%124 = load i8*, i8** %6
%125 = load i8*, i8** %7
%126 = call i32 @strcat(i8* %124, i8* %125)
br label %127
127: ; preds = %123
%128 = load i32, i32* %5
%129 = add nsw i32 %128, 1
store i32 %129, i32* %5
br label %10
130: ; preds = %10
%131 = load i32, i32* @vflag
%132 = icmp ne i32 %131, 0
br i1 %132, label %133, label %136
133: ; preds = %130
%134 = load i8*, i8** %6
%135 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %134)
br label %136
136: ; preds = %133, %130
%137 = load i8*, i8** %6
ret i8* %137
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%%%x\00"
@vflag = external global i32
@.str.2 = [39 x i8] c"(verbose) post-converted string: \22%s\22\0A\00"
define i8* @inet_convert(i8* %0, i32 %1) {
%3 = tail call dereferenceable_or_null(1024) i8* @calloc(i32 1024, i32 1)
%4 = tail call dereferenceable_or_null(1024) i8* @calloc(i32 1024, i32 1)
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %30
7: ; preds = %2
%8 = getelementptr i8, i8* %4, i64 1
br label %9
9: ; preds = %7, %24
%10 = phi i64 [ 0, %7 ], [ %26, %24 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %15 [
i8 32, label %13
i8 43, label %13
i8 38, label %14
i8 61, label %14
]
13: ; preds = %9, %9
store i8 43, i8* %4
store i8 0, i8* %8
br label %24
14: ; preds = %9, %9
store i8 %12, i8* %4
store i8 0, i8* %8
br label %24
15: ; preds = %9
%16 = and i8 %12, -33
%17 = add i8 %16, -65
%18 = icmp ult i8 %17, 26
br i1 %18, label %19, label %20
19: ; preds = %15
store i8 %12, i8* %4
store i8 0, i8* %8
br label %24
20: ; preds = %15
switch i32 %1, label %24 [
i32 0, label %21
i32 1, label %22
]
21: ; preds = %20
store i8 %12, i8* %4
store i8 0, i8* %8
br label %24
22: ; preds = %20
%23 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 signext %12)
br label %24
24: ; preds = %21, %20, %14, %22, %19, %13
%25 = tail call i32 @strcat(i8* %3, i8* %4)
%26 = add nuw nsw i64 %10, 1
%27 = tail call i32 @strlen(i8* %0)
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %9, label %30
30: ; preds = %24, %2
%31 = load i32, i32* @vflag
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %35
35: ; preds = %33, %30
ret i8* %3
}