#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*/ strcpy(char *, char *);
char *strstr(char *, char *);
char *find_source_file(int argc, char *argv[], char *file) {
  int i;
  char *c;
  for (i = 0; i < argc; i++) {
    if (c = strstr(argv[i], ".c")) {
      if (*(c + 2) == '\0') {
        strcpy(file, argv[i]);
        strcpy(argv[i], "-x");
        return file;
      }
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_source_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cf <find_source_file+0xaf>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xea7(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11bc <find_source_file+0x9c>
mov    -0x30(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    11b7 <find_source_file+0x97>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe5e(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <find_source_file+0xb7>
jmp    11bc <find_source_file+0x9c>
jmp    11c1 <find_source_file+0xa1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113a <find_source_file+0x1a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_source_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1190 <find_source_file+0x70>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xec2(%rip),%r15
xor    %ebx,%ebx
jmp    1159 <find_source_file+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1190 <find_source_file+0x70>
mov    (%r12,%rbx,8),%r13
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1150 <find_source_file+0x30>
cmpb   $0x0,0x2(%rax)
jne    1150 <find_source_file+0x30>
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    (%r12,%rbx,8),%rdi
lea    0xe7a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1193 <find_source_file+0x73>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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