#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*/ printf(char *);
void checkarg(int argc) {
  if (argc != 4) {
    if (argc == 1) {
      printf("Error: Arguments not supplied\n");
      printf("Usage: ./replacew <word> <File> <word2replace>\n");
      return;
    }
    if (argc == 2) {
      printf("Error: file name & word2replace not supplied\n");
      printf("Usage: ./replacew <word> <File> <word2replace>\n");
      return;
    }
    if (argc == 3) {
      printf("Error: word2replace not supplied\n");
      printf("Usage: ./replacew <word> <File> <word2replace>\n");
      return;
    } else {
      printf("Error: More than enough argument supplied\n");
      return;
    }
  }
}


x86 assembly (clang, -O0):
<checkarg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     11a6 <checkarg+0x96>
cmpl   $0x1,-0x4(%rbp)
jne    114c <checkarg+0x3c>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    0xedd(%rip),%rdi
call   1030 <printf@plt>
jmp    11a6 <checkarg+0x96>
cmpl   $0x2,-0x4(%rbp)
jne    1173 <checkarg+0x63>
lea    0xef2(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
jmp    11a6 <checkarg+0x96>
cmpl   $0x3,-0x4(%rbp)
jne    119a <checkarg+0x8a>
lea    0xef9(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
jmp    11a6 <checkarg+0x96>
lea    0xefe(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkarg>:
push   %rax
mov    %edi,%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     113b <checkarg+0x2b>
lea    0xf66(%rip),%rdi
lea    0xed7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf22(%rip),%rdi
jmp    114f <checkarg+0x3f>
lea    0xece(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
lea    0xf4b(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Error: Arguments not supplied\0A\00"
@.str.1 = [48 x i8] c"Usage: ./replacew <word> <File> <word2replace>\0A\00"
@.str.2 = [46 x i8] c"Error: file name & word2replace not supplied\0A\00"
@.str.3 = [34 x i8] c"Error: word2replace not supplied\0A\00"
@.str.4 = [43 x i8] c"Error: More than enough argument supplied\0A\00"
define void @checkarg(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp ne i32 %3, 4
br i1 %4, label %5, label %25
5: ; preds = %1
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %25
11: ; preds = %5
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %25
17: ; preds = %11
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 3
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %25
23: ; preds = %17
%24 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %25
25: ; preds = %8, %14, %20, %23, %1
ret void
}

LLVM IR (-O2):
@str = [42 x i8] c"Error: More than enough argument supplied\00"
@str.5 = [33 x i8] c"Error: word2replace not supplied\00"
@str.7 = [45 x i8] c"Error: file name & word2replace not supplied\00"
@str.9 = [30 x i8] c"Error: Arguments not supplied\00"
@str.10 = [47 x i8] c"Usage: ./replacew <word> <File> <word2replace>\00"
define void @checkarg(i32 %0) {
switch i32 %0, label %8 [
i32 4, label %11
i32 1, label %4
i32 2, label %2
i32 3, label %3
]
2: ; preds = %1
br label %4
3: ; preds = %1
br label %4
4: ; preds = %1, %2, %3
%5 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.5, i64 0, i64 0), %3 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @str.7, i64 0, i64 0), %2 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @str.9, i64 0, i64 0), %1 ]
%6 = phi i8* [ getelementptr inbounds ([47 x i8], [47 x i8]* @str.10, i64 0, i64 0), %3 ], [ getelementptr inbounds ([47 x i8], [47 x i8]* @str.10, i64 0, i64 0), %2 ], [ getelementptr inbounds ([47 x i8], [47 x i8]* @str.10, i64 0, i64 0), %1 ]
%7 = tail call i32 @puts(i8* dereferenceable(1) %5)
br label %8
8: ; preds = %4, %1
%9 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0), %1 ], [ %6, %4 ]
%10 = tail call i32 @puts(i8* dereferenceable(1) %9)
br label %11
11: ; preds = %8, %1
ret void
}