#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*/ error_exit(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *process_args(int argc, char **argv) {
  char *fname;
  int k;
  if (argc < 2)
    error_exit("Must specify input file");
  fname = argv[1];
  k = strlen(fname) - 3;
  if (k < 1 || strncmp(fname + k, ".in", 3))
    error_exit("Input file must have the '.in' extension");
  fname = (char *)malloc((k + 20) * sizeof(char));
  strcpy(fname, argv[1]);
  return fname;
}


x86 assembly (clang, -O0):
<process_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    1175 <process_args+0x25>
lea    0xe90(%rip),%rdi
call   1060 <error_exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x3,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jl     11c0 <process_args+0x70>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0xe6c(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11cc <process_args+0x7c>
lea    0xe55(%rip),%rdi
call   1060 <error_exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x14,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_args>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jg     1169 <process_args+0x19>
lea    0xe9c(%rip),%rdi
call   1060 <error_exit@plt>
mov    0x8(%r14),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
cmp    $0x4,%eax
jl     119b <process_args+0x4b>
lea    -0x3(%rbx),%eax
add    %rax,%r15
lea    0xe8f(%rip),%rsi
mov    %r15,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a7 <process_args+0x57>
lea    0xe7a(%rip),%rdi
call   1060 <error_exit@plt>
add    $0x11,%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%r14),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Must specify input file\00"
@.str.1 = [4 x i8] c".in\00"
@.str.2 = [41 x i8] c"Input file must have the '.in' extension\00"
define i8* @process_args(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @error_exit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = sub nsw i32 %16, 3
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 1
br i1 %19, label %27, label %20
20: ; preds = %11
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = call i64 @strncmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20, %11
%28 = call i32 @error_exit(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %20
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 20
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 1
%34 = trunc i64 %33 to i32
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %5
%37 = load i8*, i8** %5
%38 = load i8**, i8*** %4
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strcpy(i8* %37, i8* %40)
%42 = load i8*, i8** %5
ret i8* %42
}

LLVM IR (-O2):
@.str = [24 x i8] c"Must specify input file\00"
@.str.1 = [4 x i8] c".in\00"
@.str.2 = [41 x i8] c"Input file must have the '.in' extension\00"
define i8* @process_args(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @error_exit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strlen(i8* %8)
%10 = icmp slt i32 %9, 4
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = add nsw i32 %9, -3
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
%15 = tail call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11, %6
%18 = tail call i32 @error_exit(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
%20 = add nsw i32 %9, 17
%21 = tail call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = load i8*, i8** %7
%24 = tail call i32 @strcpy(i8* %22, i8* %23)
ret i8* %22
}