#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ HandleArgs(int, char **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strchr(char *, char);
char *trim(char *);
void HandleDefaultArgs(void) {
  static char defaultArgs[4096];
  char *argArray[50];
  FILE *def = NULL;
  int numArgs = 1;
  char *start = NULL;
  char *s = NULL;
  def = fopen("defaults.txt", "r");
  if (def == NULL)
    return;
  if (fgets(defaultArgs, 4096, def) != NULL) {
    start = trim(defaultArgs);
    do {
      s = strchr(start, ' ');
      if (s != NULL) {
        argArray[numArgs++] = start;
        *s = '\0';
        start = trim(s + 1);
      } else {
        argArray[numArgs++] = start;
        break;
      }
    } while (numArgs < 50);
    if (numArgs > 1)
      HandleArgs(numArgs, argArray);
  }
  fclose(def);
}


x86 assembly (clang, -O0):
<HandleDefaultArgs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movq   $0x0,-0x198(%rbp)
movl   $0x1,-0x19c(%rbp)
movq   $0x0,-0x1a8(%rbp)
movq   $0x0,-0x1b0(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x198(%rbp)
cmpq   $0x0,-0x198(%rbp)
jne    11c3 <HandleDefaultArgs+0x63>
jmp    12cf <HandleDefaultArgs+0x16f>
mov    -0x198(%rbp),%rdx
lea    0x2e8f(%rip),%rdi
mov    $0x1000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12c3 <HandleDefaultArgs+0x163>
lea    0x2e74(%rip),%rdi
call   1050 <trim@plt>
mov    %rax,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x1b0(%rbp)
cmpq   $0x0,-0x1b0(%rbp)
je     1266 <HandleDefaultArgs+0x106>
mov    -0x1a8(%rbp),%rcx
mov    -0x19c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x19c(%rbp)
cltq
mov    %rcx,-0x190(%rbp,%rax,8)
ff
mov    -0x1b0(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1b0(%rbp),%rdi
add    $0x1,%rdi
call   1050 <trim@plt>
mov    %rax,-0x1a8(%rbp)
jmp    128d <HandleDefaultArgs+0x12d>
mov    -0x1a8(%rbp),%rcx
mov    -0x19c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x19c(%rbp)
cltq
mov    %rcx,-0x190(%rbp,%rax,8)
ff
jmp    129f <HandleDefaultArgs+0x13f>
jmp    1292 <HandleDefaultArgs+0x132>
cmpl   $0x32,-0x19c(%rbp)
jl     11f8 <HandleDefaultArgs+0x98>
cmpl   $0x1,-0x19c(%rbp)
jle    12be <HandleDefaultArgs+0x15e>
mov    -0x19c(%rbp),%edi
lea    -0x190(%rbp),%rsi
call   1060 <HandleArgs@plt>
jmp    12c3 <HandleDefaultArgs+0x163>
mov    -0x198(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HandleDefaultArgs>:
push   %r15
push   %r14
push   %rbx
sub    $0x190,%rsp
lea    0xe8d(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1210 <HandleDefaultArgs+0xb0>
mov    %rax,%r14
lea    0x2ece(%rip),%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1208 <HandleDefaultArgs+0xa8>
lea    0x2eb5(%rip),%rdi
call   1050 <trim@plt>
mov    %rax,%r15
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f9 <HandleDefaultArgs+0x99>
mov    %r15,(%rsp,%rbx,8)
add    $0x1,%rbx
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1050 <trim@plt>
mov    %rax,%r15
cmp    $0x32,%rbx
jne    11c0 <HandleDefaultArgs+0x60>
mov    $0x32,%edi
jmp    1200 <HandleDefaultArgs+0xa0>
lea    0x1(%rbx),%edi
mov    %r15,(%rsp,%rbx,8)
mov    %rsp,%rsi
call   1060 <HandleArgs@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x190,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@HandleDefaultArgs.defaultArgs = internal global [4096 x i8] zeroinitializer
@.str = [13 x i8] c"defaults.txt\00"
@.str.1 = [2 x i8] c"r\00"
define void @HandleDefaultArgs() {
%1 = alloca [50 x i8*]
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32* null, i32** %2
store i32 1, i32* %3
store i8* null, i8** %4
store i8* null, i8** %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
br label %52
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32* @fgets(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @HandleDefaultArgs.defaultArgs, i64 0, i64 0), i32 4096, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %49
14: ; preds = %10
%15 = call i8* @trim(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @HandleDefaultArgs.defaultArgs, i64 0, i64 0))
store i8* %15, i8** %4
br label %16
16: ; preds = %38, %14
%17 = load i8*, i8** %4
%18 = call i8* @strchr(i8* %17, i8 signext 32)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %31
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 %25
store i8* %22, i8** %26
%27 = load i8*, i8** %5
store i8 0, i8* %27
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = call i8* @trim(i8* %29)
store i8* %30, i8** %4
br label %37
31: ; preds = %16
%32 = load i8*, i8** %4
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 %35
store i8* %32, i8** %36
br label %41
37: ; preds = %21
br label %38
38: ; preds = %37
%39 = load i32, i32* %3
%40 = icmp slt i32 %39, 50
br i1 %40, label %16, label %41
41: ; preds = %38, %31
%42 = load i32, i32* %3
%43 = icmp sgt i32 %42, 1
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* %3
%46 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 0
%47 = call i32 @HandleArgs(i32 %45, i8** %46)
br label %48
48: ; preds = %44, %41
br label %49
49: ; preds = %48, %10
%50 = load i32*, i32** %2
%51 = call i32 @fclose(i32* %50)
br label %52
52: ; preds = %49, %9
ret void
}

LLVM IR (-O2):
@HandleDefaultArgs.defaultArgs = internal global [4096 x i8] zeroinitializer
@.str = [13 x i8] c"defaults.txt\00"
@.str.1 = [2 x i8] c"r\00"
define void @HandleDefaultArgs() {
%1 = alloca [50 x i8*]
%2 = bitcast [50 x i8*]* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %32, label %5
5: ; preds = %0
%6 = tail call i32* @fgets(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @HandleDefaultArgs.defaultArgs, i64 0, i64 0), i32 4096, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %30, label %8
8: ; preds = %5
%9 = tail call i8* @trim(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @HandleDefaultArgs.defaultArgs, i64 0, i64 0))
br label %10
10: ; preds = %15, %8
%11 = phi i64 [ %16, %15 ], [ 1, %8 ]
%12 = phi i8* [ %19, %15 ], [ %9, %8 ]
%13 = tail call i8* @strchr(i8* dereferenceable(1) %12, i8 signext 32)
%14 = icmp eq i8* %13, null
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = add nuw nsw i64 %11, 1
%17 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 %11
store i8* %12, i8** %17
store i8 0, i8* %13
%18 = getelementptr inbounds i8, i8* %13, i64 1
%19 = tail call i8* @trim(i8* %18)
%20 = icmp eq i64 %16, 50
br i1 %20, label %26, label %10
21: ; preds = %10
%22 = trunc i64 %11 to i32
%23 = add nuw nsw i32 %22, 1
%24 = and i64 %11, 4294967295
%25 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 %24
store i8* %12, i8** %25
br label %26
26: ; preds = %15, %21
%27 = phi i32 [ %23, %21 ], [ 50, %15 ]
%28 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 0
%29 = call i32 @HandleArgs(i32 %27, i8** %28)
br label %30
30: ; preds = %26, %5
%31 = call i32 @fclose(i32* %3)
br label %32
32: ; preds = %0, %30
ret void
}