#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 PATH_MAX;
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ joinfiles(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char *argv[]) {
  FILE *of;
  if (argc != 3) {
    fprintf(stderr, "usage: jf outfile basename");
    return 1;
  }
  if (strlen(argv[2]) > (PATH_MAX - 5))
    die("name too long.");
  if (!(of = fopen(argv[1], "wb")))
    die("can't open file.");
  joinfiles(of, argv[2]);
  fclose(of);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a1 <main+0x41>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x5,%ecx
cmp    %ecx,%eax
jle    11ce <main+0x6e>
lea    0xe52(%rip),%rdi
call   1080 <die@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fc <main+0x9c>
lea    0xe36(%rip),%rdi
call   1080 <die@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1060 <joinfiles@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11cd <main+0x6d>
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
call   1040 <strlen@plt>
mov    0x2e74(%rip),%rcx
mov    (%rcx),%ecx
add    $0xfffffffb,%ecx
cmp    %ecx,%eax
jle    1191 <main+0x31>
lea    0xe8f(%rip),%rdi
call   1080 <die@plt>
mov    0x8(%r14),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b5 <main+0x55>
lea    0xe7d(%rip),%rdi
call   1080 <die@plt>
mov    0x10(%r14),%rsi
mov    %rbx,%rdi
call   1060 <joinfiles@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11e7 <main+0x87>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"usage: jf outfile basename\00"
@PATH_MAX = global i32 0
@.str.1 = [15 x i8] c"name too long.\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [17 x i8] c"can't open file.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %38
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @strlen(i8* %15)
%17 = load i32, i32* @PATH_MAX
%18 = sub nsw i32 %17, 5
%19 = icmp sgt i32 %16, %18
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %12
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %26, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = call i32 @die(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
%31 = load i32*, i32** %6
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @joinfiles(i32* %31, i8* %34)
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
store i32 0, i32* %3
br label %38
38: ; preds = %30, %9
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"usage: jf outfile basename\00"
@PATH_MAX = global i32 0
@.str.1 = [15 x i8] c"name too long.\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [17 x i8] c"can't open file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %27
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = load i32, i32* @PATH_MAX
%12 = add nsw i32 %11, -5
%13 = icmp sgt i32 %10, %12
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %7
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @die(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = load i8*, i8** %8
%25 = tail call i32 @joinfiles(i32* %19, i8* %24)
%26 = tail call i32 @fclose(i32* %19)
br label %27
27: ; preds = %23, %4
%28 = phi i32 [ 1, %4 ], [ 0, %23 ]
ret i32 %28
}