#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ parse_f(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
void parse_sourcefile(char *srcname) {
  FILE *f;
  char *s, *p;
  char origname[64];
  strcpy(origname, srcname);
  s = NULL;
  p = srcname;
  while (*p) {
    if (*p == '.')
      s = p;
    p++;
  }
  if (*s != '.') {
    fprintf(stderr, "Bad file name %s\n", srcname);
    printf("\n");
    exit(-1);
  }
  if ((f = fopen(srcname, "r")) == NULL) {
    perror(srcname);
    printf("\n");
    exit(-1);
  }
  *s++ = 0;
  printf("%s.o: %s ", srcname, origname);
  parse_f(f, ".");
  printf("\n");
  fclose(f);
}


x86 assembly (clang, -O0):
<parse_sourcefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11df <parse_sourcefile+0x5f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ce <parse_sourcefile+0x4e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a9 <parse_sourcefile+0x29>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1220 <parse_sourcefile+0xa0>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdfd(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    125f <parse_sourcefile+0xdf>
mov    -0x8(%rbp),%rdi
call   1090 <perror@plt>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xd8c(%rip),%rsi
call   1070 <parse_f@plt>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_sourcefile>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
xor    %ebx,%ebx
mov    %r14,%rax
jmp    11b7 <parse_sourcefile+0x27>
xchg   %ax,%ax
mov    %rax,%rbx
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x2e,%cl
je     11b0 <parse_sourcefile+0x20>
test   %cl,%cl
jne    11b3 <parse_sourcefile+0x23>
cmpb   $0x2e,(%rbx)
jne    1221 <parse_sourcefile+0x91>
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     123b <parse_sourcefile+0xab>
mov    %rax,%r15
movb   $0x0,(%rbx)
lea    0xe2b(%rip),%rdi
mov    %rsp,%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe21(%rip),%rsi
mov    %r15,%rdi
call   1080 <parse_f@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
jmp    1243 <parse_sourcefile+0xb3>
mov    %r14,%rdi
call   10a0 <perror@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Bad file name %s\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [10 x i8] c"%s.o: %s \00"
@.str.4 = [2 x i8] c".\00"
define void @parse_sourcefile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [64 x i8]
store i8* %0, i8** %2
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = call i32 @strcpy(i8* %7, i8* %8)
store i8* null, i8** %4
%10 = load i8*, i8** %2
store i8* %10, i8** %5
br label %11
11: ; preds = %22, %1
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 46
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i8*, i8** %5
store i8* %21, i8** %4
br label %22
22: ; preds = %20, %15
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
br label %11
25: ; preds = %11
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 46
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %2
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %25
%37 = load i8*, i8** %2
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %3
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i8*, i8** %2
%42 = call i32 @perror(i8* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %36
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
store i8 0, i8* %46
%48 = load i8*, i8** %2
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %48, i8* %49)
%51 = load i32*, i32** %3
%52 = call i32 @parse_f(i32* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%54 = load i32*, i32** %3
%55 = call i32 @fclose(i32* %54)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Bad file name %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [10 x i8] c"%s.o: %s \00"
@.str.4 = [2 x i8] c".\00"
define void @parse_sourcefile(i8* %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
br label %5
5: ; preds = %10, %1
%6 = phi i8* [ null, %1 ], [ %11, %10 ]
%7 = phi i8* [ %0, %1 ], [ %12, %10 ]
%8 = load i8, i8* %7
switch i8 %8, label %10 [
i8 0, label %13
i8 46, label %9
]
9: ; preds = %5
br label %10
10: ; preds = %5, %9
%11 = phi i8* [ %7, %9 ], [ %6, %5 ]
%12 = getelementptr inbounds i8, i8* %7, i64 1
br label %5
13: ; preds = %5
%14 = load i8, i8* %6
%15 = icmp eq i8 %14, 46
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
%19 = call i32 @putchar(i32 10)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %13
%22 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = call i32 @perror(i8* %0)
%26 = call i32 @putchar(i32 10)
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %21
store i8 0, i8* %6
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %3)
%30 = call i32 @parse_f(i32* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @putchar(i32 10)
%32 = call i32 @fclose(i32* %22)
ret void
}