#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*/ print_help();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ run_caesar(char *, int);
int sscanf(char *, char *, int *);
int strlen(char *);
void parse_args(int argc, char **argv) {
  if (argc == 1) {
    printf("\"shift\" and \"text\" arguments are missing\n");
    goto error;
  } else if (argc == 2) {
    printf("\"text\" argument is missing\n");
    goto error;
  } else if (argc > 3) {
    printf("Too many arguments\n");
    goto error;
  }
  int shift;
  int result = sscanf(argv[1], "%d", &shift);
  if (result != 1) {
    printf("\"shift\" argument must be an integer\n");
    goto error;
  }
  char *input = argv[2];
  if (strlen(input) < 1) {
    printf("\"input\" must have at least one character\n");
    goto error;
  }
  run_caesar(input, shift);
  return;
error:
  print_help();
}


x86 assembly (clang, -O0):
<parse_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    117a <parse_args+0x2a>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
jmp    1230 <parse_args+0xe0>
cmpl   $0x2,-0x4(%rbp)
jne    1195 <parse_args+0x45>
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
jmp    1230 <parse_args+0xe0>
cmpl   $0x3,-0x4(%rbp)
jle    11b0 <parse_args+0x60>
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
jmp    1230 <parse_args+0xe0>
jmp    11b5 <parse_args+0x65>
jmp    11ba <parse_args+0x6a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe91(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     11f0 <parse_args+0xa0>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
jmp    1230 <parse_args+0xe0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jge    121f <parse_args+0xcf>
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
jmp    1230 <parse_args+0xe0>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <run_caesar@plt>
jmp    1237 <parse_args+0xe7>
mov    $0x0,%al
call   1070 <print_help@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_args>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
je     1168 <parse_args+0x18>
cmp    $0x1,%edi
jne    1171 <parse_args+0x21>
lea    0xf18(%rip),%rdi
jmp    11ca <parse_args+0x7a>
lea    0xef4(%rip),%rdi
jmp    11ca <parse_args+0x7a>
cmp    $0x4,%edi
jl     117f <parse_args+0x2f>
lea    0xed3(%rip),%rdi
jmp    11ca <parse_args+0x7a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe73(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11ba <parse_args+0x6a>
mov    0x10(%rbx),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c3 <parse_args+0x73>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1060 <run_caesar@plt>
jmp    11d6 <parse_args+0x86>
lea    0xe6b(%rip),%rdi
jmp    11ca <parse_args+0x7a>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <print_help@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"\22shift\22 and \22text\22 arguments are missing\0A\00"
@.str.1 = [28 x i8] c"\22text\22 argument is missing\0A\00"
@.str.2 = [20 x i8] c"Too many arguments\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [37 x i8] c"\22shift\22 argument must be an integer\0A\00"
@.str.5 = [42 x i8] c"\22input\22 must have at least one character\0A\00"
define void @parse_args(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %46
12: ; preds = %2
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %46
17: ; preds = %12
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 3
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %46
22: ; preds = %17
br label %23
23: ; preds = %22
br label %24
24: ; preds = %23
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %46
33: ; preds = %24
%34 = load i8**, i8*** %4
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = call i32 @strlen(i8* %37)
%39 = icmp slt i32 %38, 1
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
br label %46
42: ; preds = %33
%43 = load i8*, i8** %7
%44 = load i32, i32* %5
%45 = call i32 @run_caesar(i8* %43, i32 %44)
br label %48
46: ; preds = %40, %31, %20, %15, %10
%47 = call i32 (...) @print_help()
br label %48
48: ; preds = %46, %42
ret void
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"%d\00"
@str = [41 x i8] c"\22input\22 must have at least one character\00"
@str.6 = [36 x i8] c"\22shift\22 argument must be an integer\00"
@str.7 = [19 x i8] c"Too many arguments\00"
@str.8 = [27 x i8] c"\22text\22 argument is missing\00"
@str.9 = [41 x i8] c"\22shift\22 and \22text\22 arguments are missing\00"
define void @parse_args(i32 %0, i8** nocapture %1) {
%3 = alloca i32
switch i32 %0, label %8 [
i32 1, label %4
i32 2, label %6
]
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.9, i64 0, i64 0))
br label %29
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.8, i64 0, i64 0))
br label %29
8: ; preds = %2
%9 = icmp sgt i32 %0, 3
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
br label %29
12: ; preds = %8
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.6, i64 0, i64 0))
br label %29
19: ; preds = %12
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @strlen(i8* %21)
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %29
26: ; preds = %19
%27 = load i32, i32* %3
%28 = call i32 @run_caesar(i8* %21, i32 %27)
br label %31
29: ; preds = %24, %17, %10, %6, %4
%30 = call i32 (...) @print_help()
br label %31
31: ; preds = %29, %26
ret void
}