#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 */
char *strstr(char *, char *);
long long strtoll(char *, int /*<<< orphan*/ *, int);
char *find_first_arg(int argc, char **argv,
                     long long int *truncation_location) {
  int i;
  for (i = 1; i < argc; ++i) {
    if (strstr(argv[i], "-trunc=") == argv[i]) {
      *truncation_location = strtoll(argv[i] + 7, NULL, 10);
    }
  }
  for (i = 1; i < argc; ++i) {
    if (argv[i][0] != '-') {
      return argv[i];
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_first_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ab <find_first_arg+0x8b>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xea7(%rip),%rsi
call   1040 <strstr@plt>
mov    -0x18(%rbp),%rcx
movslq -0x24(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
jne    1198 <find_first_arg+0x78>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x7,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    119d <find_first_arg+0x7d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113a <find_first_arg+0x1a>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fe <find_first_arg+0xde>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11eb <find_first_arg+0xcb>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    1206 <find_first_arg+0xe6>
jmp    11f0 <find_first_arg+0xd0>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b2 <find_first_arg+0x92>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_first_arg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11b3 <find_first_arg+0x93>
mov    %rdx,%r14
mov    %rsi,%r13
mov    %edi,0x4(%rsp)
mov    %edi,%ebx
mov    $0x1,%r15d
lea    0xeb3(%rip),%r12
jmp    1159 <find_first_arg+0x39>
nop
add    $0x1,%r15
cmp    %r15,%rbx
je     118a <find_first_arg+0x6a>
mov    0x0(%r13,%r15,8),%rbp
mov    $0x7,%edx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1150 <find_first_arg+0x30>
add    $0x7,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoll@plt>
mov    %rax,(%r14)
jmp    1150 <find_first_arg+0x30>
cmpl   $0x2,0x4(%rsp)
jl     11b3 <find_first_arg+0x93>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13,%rcx,8),%rax
cmpb   $0x2d,(%rax)
jne    11b5 <find_first_arg+0x95>
add    $0x1,%rcx
cmp    %rcx,%rbx
jne    11a0 <find_first_arg+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"-trunc=\00"
define i8* @find_first_arg(i32 %0, i8** %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
store i32 1, i32* %8
br label %9
9: ; preds = %36, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %39
13: ; preds = %9
%14 = load i8**, i8*** %6
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%20 = load i8**, i8*** %6
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = icmp eq i8* %19, %24
br i1 %25, label %26, label %35
26: ; preds = %13
%27 = load i8**, i8*** %6
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i64 7
%33 = call i64 @strtoll(i8* %32, i32* null, i32 10)
%34 = load i64*, i64** %7
store i64 %33, i64* %34
br label %35
35: ; preds = %26, %13
br label %36
36: ; preds = %35
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %9
39: ; preds = %9
store i32 1, i32* %8
br label %40
40: ; preds = %61, %39
%41 = load i32, i32* %8
%42 = load i32, i32* %5
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %64
44: ; preds = %40
%45 = load i8**, i8*** %6
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = getelementptr inbounds i8, i8* %49, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 45
br i1 %53, label %54, label %60
54: ; preds = %44
%55 = load i8**, i8*** %6
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
store i8* %59, i8** %4
br label %65
60: ; preds = %44
br label %61
61: ; preds = %60
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
br label %40
64: ; preds = %40
store i8* null, i8** %4
br label %65
65: ; preds = %64, %54
%66 = load i8*, i8** %4
ret i8* %66
}

LLVM IR (-O2):
@.str = [8 x i8] c"-trunc=\00"
define i8* @find_first_arg(i32 %0, i8** nocapture %1, i64* nocapture writeonly %2) {
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %31
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %10
7: ; preds = %19
br i1 %4, label %8, label %31
8: ; preds = %7
%9 = zext i32 %0 to i64
br label %24
10: ; preds = %5, %19
%11 = phi i64 [ 1, %5 ], [ %20, %19 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 @strncmp(i8* dereferenceable(1) %13, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %13, i64 7
%18 = tail call i64 @strtoll(i8* nocapture %17, i32* null, i32 10)
store i64 %18, i64* %2
br label %19
19: ; preds = %10, %16
%20 = add nuw nsw i64 %11, 1
%21 = icmp eq i64 %20, %6
br i1 %21, label %7, label %10
22: ; preds = %24
%23 = icmp eq i64 %30, %9
br i1 %23, label %31, label %24
24: ; preds = %8, %22
%25 = phi i64 [ 1, %8 ], [ %30, %22 ]
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 45
%30 = add nuw nsw i64 %25, 1
br i1 %29, label %22, label %31
31: ; preds = %24, %22, %3, %7
%32 = phi i8* [ null, %7 ], [ null, %3 ], [ null, %22 ], [ %27, %24 ]
ret i8* %32
}