#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Takes exactly 2 arguments\n");
    return 1;
  }
  char *dirname = getenv("MESON_INSTALL_DESTDIR_PREFIX");
  char *fullname = malloc(strlen(dirname) + 1 + strlen(argv[1]) + 1);
  strcpy(fullname, dirname);
  strcat(fullname, "/");
  strcat(fullname, argv[1]);
  FILE *fp = fopen(fullname, "w");
  if (!fp)
    return 1;
  fputs("Some text\n", fp);
  fclose(fp);
  free(fullname);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e1 <main+0x41>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a5 <main+0x105>
lea    0xe33(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10c0 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    127c <main+0xdc>
movl   $0x1,-0x4(%rbp)
jmp    12a5 <main+0x105>
mov    -0x28(%rbp),%rsi
lea    0xdb5(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    124e <main+0xae>
mov    %rsi,%r14
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbx
mov    0x8(%r14),%rdi
call   1070 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
lea    0xe42(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1263 <main+0xc3>
mov    %rax,%r14
lea    0xe14(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    1268 <main+0xc8>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Takes exactly 2 arguments\0A\00"
@.str.1 = [29 x i8] c"MESON_INSTALL_DESTDIR_PREFIX\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [11 x i8] c"Some text\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %48
14: ; preds = %2
%15 = call i8* @getenv(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %18, %22
%24 = add nsw i64 %23, 1
%25 = call i8* @malloc(i64 %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = load i8*, i8** %6
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = load i8*, i8** %7
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%31 = load i8*, i8** %7
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @strcat(i8* %31, i8* %34)
%36 = load i8*, i8** %7
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %37, i32** %8
%38 = load i32*, i32** %8
%39 = icmp ne i32* %38, null
br i1 %39, label %41, label %40
40: ; preds = %14
store i32 1, i32* %3
br label %48
41: ; preds = %14
%42 = load i32*, i32** %8
%43 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32* %42)
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
%46 = load i8*, i8** %7
%47 = call i32 @free(i8* %46)
store i32 0, i32* %3
br label %48
48: ; preds = %41, %40, %11
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Takes exactly 2 arguments\0A\00"
@.str.1 = [29 x i8] c"MESON_INSTALL_DESTDIR_PREFIX\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [11 x i8] c"Some text\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
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 %26
7: ; preds = %2
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = add i64 %9, 2
%14 = add i64 %13, %12
%15 = tail call i8* @malloc(i64 %14)
%16 = tail call i32 @strcpy(i8* %15, i8* %8)
%17 = tail call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = load i8*, i8** %10
%19 = tail call i32 @strcat(i8* %15, i8* %18)
%20 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %7
%23 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i64 10, i64 1, i32* %20)
%24 = tail call i32 @fclose(i32* %20)
%25 = tail call i32 @free(i8* %15)
br label %26
26: ; preds = %22, %7, %4
%27 = phi i32 [ 1, %4 ], [ 0, %22 ], [ 1, %7 ]
ret i32 %27
}