#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*/ memcpy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Insufficient Arguments,\nUsage: ./DhcpStringCalc \"2001::21 "
           "10.2.3.2 24\" \"1 or 2 or 3\" \n");
    exit(-1);
  }
  char *pch1;
  char s[120];
  memcpy(s, argv[1], strlen(argv[1]));
  char *str1 = s;
  pch1 = strtok(str1, " ");
  char outStr[10][50], i = 0;
  while (pch1 != NULL) {
    strcpy(outStr[i++], pch1);
    pch1 = strtok(NULL, " ");
  }
  if (!strcmp(argv[2], "1"))
    printf("%s\n", outStr[0]);
  else if (!strcmp(argv[2], "2"))
    printf("%s\n", outStr[1]);
  else if (!strcmp(argv[2], "3"))
    printf("%s\n", outStr[2]);
  else
    printf(
        "I am expecting three parameters in a string separated with a space\n");
  i = 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ab <main+0x3b>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x2a8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x2a0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x2a8(%rbp),%rdi
mov    -0x2a0(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x291(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1266 <main+0xf6>
mov    -0x291(%rbp),%al
mov    %al,%cl
add    $0x1,%cl
mov    %cl,-0x291(%rbp)
movsbq %al,%rax
lea    -0x290(%rbp),%rdi
imul   $0x32,%rax,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdff(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1216 <main+0xa6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xde4(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    129d <main+0x12d>
lea    -0x290(%rbp),%rsi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    132b <main+0x1bb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdb3(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12d8 <main+0x168>
lea    -0x290(%rbp),%rsi
add    $0x32,%rsi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1326 <main+0x1b6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd7a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1313 <main+0x1a3>
lea    -0x290(%rbp),%rsi
add    $0x64,%rsi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1321 <main+0x1b1>
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1326 <main+0x1b6>
jmp    132b <main+0x1bb>
movb   $0x0,-0x291(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x280,%rsp
cmp    $0x2,%edi
jle    1273 <main+0x103>
mov    %rsi,%r14
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
lea    0xef2(%rip),%rsi
mov    %r15,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     11fd <main+0x8d>
xor    %ebx,%ebx
lea    0xedc(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbq %bl,%rcx
add    $0x1,%bl
imul   $0x32,%rcx,%rcx
lea    (%rsp,%rcx,1),%rdi
add    $0x80,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
jne    11d0 <main+0x60>
mov    0x10(%r14),%rbx
lea    0xdf8(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1243 <main+0xd3>
lea    0xde7(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     124d <main+0xdd>
lea    0xdd6(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1257 <main+0xe7>
lea    0xdc5(%rip),%rdi
jmp    125f <main+0xef>
lea    0x80(%rsp),%rdi
jmp    125f <main+0xef>
lea    0xb2(%rsp),%rdi
jmp    125f <main+0xef>
lea    0xe4(%rsp),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x280,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdcf(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [87 x i8] c"Insufficient Arguments,\0AUsage: ./DhcpStringCalc \222001::21 10.2.3.2 24\22 \221 or 2 or 3\22 \0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"2\00"
@.str.5 = [2 x i8] c"3\00"
@.str.6 = [68 x i8] c"I am expecting three parameters in a string separated with a space\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [120 x i8]
%8 = alloca i8*
%9 = alloca [10 x [50 x i8]]
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @memcpy(i8* %17, i8* %20, i32 %24)
%26 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = call i8* @strtok(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %28, i8** %6
store i8 0, i8* %10
br label %29
29: ; preds = %32, %16
%30 = load i8*, i8** %6
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load i8, i8* %10
%34 = add i8 %33, 1
store i8 %34, i8* %10
%35 = sext i8 %33 to i64
%36 = getelementptr inbounds [10 x [50 x i8]], [10 x [50 x i8]]* %9, i64 0, i64 %35
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %36, i64 0, i64 0
%38 = load i8*, i8** %6
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %40, i8** %6
br label %29
41: ; preds = %29
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %41
%48 = getelementptr inbounds [10 x [50 x i8]], [10 x [50 x i8]]* %9, i64 0, i64 0
%49 = getelementptr inbounds [50 x i8], [50 x i8]* %48, i64 0, i64 0
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %49)
br label %75
51: ; preds = %41
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %61, label %57
57: ; preds = %51
%58 = getelementptr inbounds [10 x [50 x i8]], [10 x [50 x i8]]* %9, i64 0, i64 1
%59 = getelementptr inbounds [50 x i8], [50 x i8]* %58, i64 0, i64 0
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %59)
br label %74
61: ; preds = %51
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
%65 = call i32 @strcmp(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%66 = icmp ne i32 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %61
%68 = getelementptr inbounds [10 x [50 x i8]], [10 x [50 x i8]]* %9, i64 0, i64 2
%69 = getelementptr inbounds [50 x i8], [50 x i8]* %68, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %69)
br label %73
71: ; preds = %61
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.6, i64 0, i64 0))
br label %73
73: ; preds = %71, %67
br label %74
74: ; preds = %73, %57
br label %75
75: ; preds = %74, %47
store i8 0, i8* %10
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"1\00"
@.str.4 = [2 x i8] c"2\00"
@.str.5 = [2 x i8] c"3\00"
@str = [67 x i8] c"I am expecting three parameters in a string separated with a space\00"
@str.7 = [86 x i8] c"Insufficient Arguments,\0AUsage: ./DhcpStringCalc \222001::21 10.2.3.2 24\22 \221 or 2 or 3\22 \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [120 x i8]
%4 = alloca [10 x [50 x i8]]
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @str.7, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @strlen(i8* %12)
%14 = call i32 @memcpy(i8* %10, i8* %12, i32 %13)
%15 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [10 x [50 x i8]], [10 x [50 x i8]]* %4, i64 0, i64 0, i64 0
%17 = icmp eq i8* %15, null
br i1 %17, label %27, label %18
18: ; preds = %9, %18
%19 = phi i8 [ %21, %18 ], [ 0, %9 ]
%20 = phi i8* [ %25, %18 ], [ %15, %9 ]
%21 = add i8 %19, 1
%22 = sext i8 %19 to i64
%23 = getelementptr inbounds [10 x [50 x i8]], [10 x [50 x i8]]* %4, i64 0, i64 %22, i64 0
%24 = call i32 @strcpy(i8* %23, i8* %20)
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %18
27: ; preds = %18, %9
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* dereferenceable(1) %29, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @puts(i8* %16)
br label %48
34: ; preds = %27
%35 = call i32 @strcmp(i8* dereferenceable(1) %29, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = getelementptr inbounds [10 x [50 x i8]], [10 x [50 x i8]]* %4, i64 0, i64 1, i64 0
%39 = call i32 @puts(i8* %38)
br label %48
40: ; preds = %34
%41 = call i32 @strcmp(i8* dereferenceable(1) %29, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = getelementptr inbounds [10 x [50 x i8]], [10 x [50 x i8]]* %4, i64 0, i64 2, i64 0
%45 = call i32 @puts(i8* %44)
br label %48
46: ; preds = %40
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %37, %46, %43, %32
ret i32 0
}