#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 */
long atol(char *);
int /*<<< orphan*/ isdigit(char const);
int /*<<< orphan*/ print_usage_and_exit(char *);
scalar_t__ strcmp(char const *, char *);
long strlen(char const *);
void validate_args_or_die(int argc, char **argv, long *offset_p,
                          char **path_p) {
  if (argc != 4) {
    print_usage_and_exit("exactly three args required");
  }
  const char *offset_label_string = argv[1];
  const char *offset_string = argv[2];
  const char *path = argv[3];
  if (strcmp(offset_label_string, "--offset") != 0) {
    print_usage_and_exit("the first arg must be \"--offset\"");
  }
  long offset_string_length = strlen(offset_string);
  if (offset_string_length == 0) {
    print_usage_and_exit("the offset arg must contain digits");
  }
  if (offset_string_length > 18) {
    print_usage_and_exit("the offset arg must contain at most 18 digits");
  }
  for (long i = 0; i < strlen(offset_string); i++) {
    if (!isdigit(offset_string[i])) {
      print_usage_and_exit("the offset arg must only contain digits");
    }
  }
  *offset_p = atol(argv[2]);
  *path_p = argv[3];
}


x86 assembly (clang, -O0):
<validate_args_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     117d <validate_args_or_die+0x2d>
lea    0xe88(%rip),%rdi
call   1050 <print_usage_and_exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11c7 <validate_args_or_die+0x77>
lea    0xe63(%rip),%rdi
call   1050 <print_usage_and_exit@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11eb <validate_args_or_die+0x9b>
lea    0xe60(%rip),%rdi
call   1050 <print_usage_and_exit@plt>
cmpq   $0x12,-0x40(%rbp)
jle    1202 <validate_args_or_die+0xb2>
lea    0xe6c(%rip),%rdi
call   1050 <print_usage_and_exit@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jge    1267 <validate_args_or_die+0x117>
mov    -0x30(%rbp),%rax
mov    -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1251 <validate_args_or_die+0x101>
lea    0xe4b(%rip),%rdi
call   1050 <print_usage_and_exit@plt>
jmp    1256 <validate_args_or_die+0x106>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    120a <validate_args_or_die+0xba>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atol@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_args_or_die>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
cmp    $0x4,%edi
je     1175 <validate_args_or_die+0x25>
lea    0xe90(%rip),%rdi
call   1050 <print_usage_and_exit@plt>
mov    0x8(%r12),%rdi
mov    0x10(%r12),%rbx
lea    0xe96(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     119c <validate_args_or_die+0x4c>
lea    0xe8e(%rip),%rdi
call   1050 <print_usage_and_exit@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     11b8 <validate_args_or_die+0x68>
cmp    $0x13,%rax
jl     11c4 <validate_args_or_die+0x74>
lea    0xeb3(%rip),%rdi
jmp    11bf <validate_args_or_die+0x6f>
lea    0xe87(%rip),%rdi
call   1050 <print_usage_and_exit@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    1208 <validate_args_or_die+0xb8>
xor    %ebp,%ebp
lea    0xebd(%rip),%r13
jmp    11f1 <validate_args_or_die+0xa1>
nopl   0x0(%rax)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbp
jge    1208 <validate_args_or_die+0xb8>
movsbl (%rbx,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
jne    11e0 <validate_args_or_die+0x90>
mov    %r13,%rdi
call   1050 <print_usage_and_exit@plt>
jmp    11e0 <validate_args_or_die+0x90>
mov    0x10(%r12),%rdi
call   1070 <atol@plt>
mov    %rax,(%r15)
mov    0x18(%r12),%rax
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"exactly three args required\00"
@.str.1 = [9 x i8] c"--offset\00"
@.str.2 = [33 x i8] c"the first arg must be \22--offset\22\00"
@.str.3 = [35 x i8] c"the offset arg must contain digits\00"
@.str.4 = [46 x i8] c"the offset arg must contain at most 18 digits\00"
@.str.5 = [40 x i8] c"the offset arg must only contain digits\00"
define void @validate_args_or_die(i32 %0, i8** %1, i64* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
store i8** %3, i8*** %8
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 @print_usage_and_exit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %4
%19 = load i8**, i8*** %6
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %9
%22 = load i8**, i8*** %6
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
store i8* %24, i8** %10
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
store i8* %27, i8** %11
%28 = load i8*, i8** %9
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %18
%32 = call i32 @print_usage_and_exit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %18
%34 = load i8*, i8** %10
%35 = call i64 @strlen(i8* %34)
store i64 %35, i64* %12
%36 = load i64, i64* %12
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @print_usage_and_exit(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = load i64, i64* %12
%42 = icmp sgt i64 %41, 18
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @print_usage_and_exit(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
store i64 0, i64* %13
br label %46
46: ; preds = %61, %45
%47 = load i64, i64* %13
%48 = load i8*, i8** %10
%49 = call i64 @strlen(i8* %48)
%50 = icmp slt i64 %47, %49
br i1 %50, label %51, label %64
51: ; preds = %46
%52 = load i8*, i8** %10
%53 = load i64, i64* %13
%54 = getelementptr inbounds i8, i8* %52, i64 %53
%55 = load i8, i8* %54
%56 = call i32 @isdigit(i8 signext %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %51
%59 = call i32 @print_usage_and_exit(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %58, %51
br label %61
61: ; preds = %60
%62 = load i64, i64* %13
%63 = add nsw i64 %62, 1
store i64 %63, i64* %13
br label %46
64: ; preds = %46
%65 = load i8**, i8*** %6
%66 = getelementptr inbounds i8*, i8** %65, i64 2
%67 = load i8*, i8** %66
%68 = call i64 @atol(i8* %67)
%69 = load i64*, i64** %7
store i64 %68, i64* %69
%70 = load i8**, i8*** %6
%71 = getelementptr inbounds i8*, i8** %70, i64 3
%72 = load i8*, i8** %71
%73 = load i8**, i8*** %8
store i8* %72, i8** %73
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"exactly three args required\00"
@.str.1 = [9 x i8] c"--offset\00"
@.str.2 = [33 x i8] c"the first arg must be \22--offset\22\00"
@.str.3 = [35 x i8] c"the offset arg must contain digits\00"
@.str.4 = [46 x i8] c"the offset arg must contain at most 18 digits\00"
@.str.5 = [40 x i8] c"the offset arg must only contain digits\00"
define void @validate_args_or_die(i32 %0, i8** nocapture %1, i64* nocapture writeonly %2, i8** nocapture writeonly %3) {
%5 = icmp eq i32 %0, 4
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 @print_usage_and_exit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %8
%16 = tail call i32 @print_usage_and_exit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %8
%18 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = icmp sgt i64 %18, 18
br i1 %21, label %22, label %25
22: ; preds = %20, %17
%23 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), %17 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), %20 ]
%24 = tail call i32 @print_usage_and_exit(i8* %23)
br label %25
25: ; preds = %22, %20
%26 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %41, %25
%29 = getelementptr inbounds i8*, i8** %1, i64 3
%30 = load i8*, i8** %11
%31 = tail call i64 @atol(i8* %30)
store i64 %31, i64* %2
%32 = load i8*, i8** %29
store i8* %32, i8** %3
ret void
33: ; preds = %25, %41
%34 = phi i64 [ %42, %41 ], [ 0, %25 ]
%35 = getelementptr inbounds i8, i8* %12, i64 %34
%36 = load i8, i8* %35
%37 = tail call i32 @isdigit(i8 signext %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = tail call i32 @print_usage_and_exit(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %33, %39
%42 = add nuw nsw i64 %34, 1
%43 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%44 = icmp slt i64 %42, %43
br i1 %44, label %33, label %28
}