#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
FILE *open_tex_output(char *fname) {
  FILE *out;
  char ofname[512];
  char *p;
  strcpy(ofname, fname);
  for (p = ofname + strlen(ofname); p != ofname && *p != '.'; --p)
    ;
  if (*p == '.')
    strcpy(p, ".tex");
  else
    strcat(ofname, ".tex");
  out = fopen(ofname, "w");
  if (!out) {
    fprintf(stderr, "Could not open output %s\n", ofname);
    exit(-1);
  }
  return out;
}


x86 assembly (clang, -O0):
<open_tex_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x220(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rcx
lea    -0x210(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x221(%rbp)
je     11e4 <open_tex_output+0x84>
mov    -0x218(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x221(%rbp)
mov    -0x221(%rbp),%al
test   $0x1,%al
jne    11f7 <open_tex_output+0x97>
jmp    1213 <open_tex_output+0xb3>
jmp    11fc <open_tex_output+0x9c>
mov    -0x218(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x218(%rbp)
jmp    11af <open_tex_output+0x4f>
mov    -0x218(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    123e <open_tex_output+0xde>
mov    -0x218(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1251 <open_tex_output+0xf1>
lea    -0x210(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x210(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1299 <open_tex_output+0x139>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    -0x210(%rbp),%rdx
lea    0xd7d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_tex_output>:
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
test   %eax,%eax
je     11a3 <open_tex_output+0x43>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x2e,(%rsp,%rax,1)
je     11bd <open_tex_output+0x5d>
add    $0xffffffffffffffff,%rax
jne    1190 <open_tex_output+0x30>
cmpb   $0x2e,(%rbx)
jne    11ac <open_tex_output+0x4c>
jmp    11c1 <open_tex_output+0x61>
lea    (%rsp,%rax,1),%rbx
cmpb   $0x2e,(%rbx)
je     11c1 <open_tex_output+0x61>
lea    0xe4d(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strcat@plt>
jmp    11d0 <open_tex_output+0x70>
lea    (%rsp,%rax,1),%rbx
lea    0xe38(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe2e(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ed <open_tex_output+0x8d>
add    $0x200,%rsp
pop    %rbx
ret
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    %rsp,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c".tex\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Could not open output %s\0A\00"
define i32* @open_tex_output(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [512 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @strcpy(i8* %6, i8* %7)
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
store i8* %13, i8** %5
br label %14
14: ; preds = %26, %1
%15 = load i8*, i8** %5
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%17 = icmp ne i8* %15, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 46
br label %23
23: ; preds = %18, %14
%24 = phi i1 [ false, %14 ], [ %22, %18 ]
br i1 %24, label %25, label %29
25: ; preds = %23
br label %26
26: ; preds = %25
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %5
br label %14
29: ; preds = %23
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 46
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i8*, i8** %5
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %40
37: ; preds = %29
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %37, %34
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %42, i32** %3
%43 = load i32*, i32** %3
%44 = icmp ne i32* %43, null
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%48 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %40
%51 = load i32*, i32** %3
ret i32* %51
}

LLVM IR (-O2):
@.str = [5 x i8] c".tex\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Could not open output %s\0A\00"
define noalias i32* @open_tex_output(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i32 @strlen(i8* %4)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %7
%9 = icmp eq i32 %6, 0
br i1 %9, label %17, label %10
10: ; preds = %1, %14
%11 = phi i8* [ %15, %14 ], [ %8, %1 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 46
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %11, i64 -1
%16 = icmp eq i8* %15, %4
br i1 %16, label %17, label %10
17: ; preds = %14, %1
%18 = phi i8* [ %8, %1 ], [ %3, %14 ]
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 46
br i1 %20, label %21, label %24
21: ; preds = %10, %17
%22 = phi i8* [ %18, %17 ], [ %11, %10 ]
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %26
24: ; preds = %17
%25 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %26
ret i32* %27
}