#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 strlen(char *);
char *detect_filename(int argc, char **argv) {
  for (int i = 1; i < argc; i++) {
    if (strlen(argv[i]) > 1 && argv[i][0] != '-') {
      return argv[i];
    }
  }
  return (char *)0;
}


x86 assembly (clang, -O0):
<detect_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118c <detect_filename+0x7c>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jle    1179 <detect_filename+0x69>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1179 <detect_filename+0x69>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    1194 <detect_filename+0x84>
jmp    117e <detect_filename+0x6e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1126 <detect_filename+0x16>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_filename>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jl     1152 <detect_filename+0x42>
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x1,%ebx
jmp    1139 <detect_filename+0x29>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1152 <detect_filename+0x42>
mov    (%r15,%rbx,8),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1130 <detect_filename+0x20>
mov    (%r15,%rbx,8),%rax
cmpb   $0x2d,(%rax)
je     1130 <detect_filename+0x20>
jmp    1154 <detect_filename+0x44>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @detect_filename(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %7
7: ; preds = %36, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %39
11: ; preds = %7
%12 = load i8**, i8*** %5
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %35
19: ; preds = %11
%20 = load i8**, i8*** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 45
br i1 %28, label %29, label %35
29: ; preds = %19
%30 = load i8**, i8*** %5
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
store i8* %34, i8** %3
br label %40
35: ; preds = %19, %11
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %7
39: ; preds = %7
store i8* null, i8** %3
br label %40
40: ; preds = %39, %29
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
define i8* @detect_filename(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %16
%7 = phi i64 [ 1, %4 ], [ %17, %16 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i8*, i8** %8
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 45
br i1 %15, label %16, label %19
16: ; preds = %6, %12
%17 = add nuw nsw i64 %7, 1
%18 = icmp eq i64 %17, %5
br i1 %18, label %19, label %6
19: ; preds = %16, %12, %2
%20 = phi i8* [ null, %2 ], [ %13, %12 ], [ null, %16 ]
ret i8* %20
}