#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 *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ get_temp_dir();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
void save_string_in_file(char *filename, char *s) {
  char fname[400];
  strcpy(fname, get_temp_dir());
  strcat(fname, filename);
  FILE *f = fopen(fname, "w");
  if (f == NULL) {
    fprintf(stderr, "can't open %s\n", filename);
    return;
  }
  fputs(s, f);
  fclose(f);
}


x86 assembly (clang, -O0):
<save_string_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1a0(%rbp),%rax
mov    %rax,-0x1b0(%rbp)
mov    $0x0,%al
call   1030 <get_temp_dir@plt>
mov    -0x1b0(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x1a0(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x1a8(%rbp)
cmpq   $0x0,-0x1a8(%rbp)
jne    11fc <save_string_in_file+0x8c>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe10(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1218 <save_string_in_file+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x1a8(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x1a8(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_string_in_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x190,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <get_temp_dir@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11cd <save_string_in_file+0x5d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11e5 <save_string_in_file+0x75>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
add    $0x190,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"can't open %s\0A\00"
define void @save_string_in_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [400 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [400 x i8], [400 x i8]* %5, i64 0, i64 0
%8 = call i32 (...) @get_temp_dir()
%9 = call i32 @strcpy(i8* %7, i32 %8)
%10 = getelementptr inbounds [400 x i8], [400 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @strcat(i8* %10, i8* %11)
%13 = getelementptr inbounds [400 x i8], [400 x i8]* %5, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %27
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = load i32*, i32** %6
%24 = call i32 @fputs(i8* %22, i32* %23)
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %21, %17
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"can't open %s\0A\00"
define void @save_string_in_file(i8* %0, i8* nocapture %1) {
%3 = alloca [400 x i8]
%4 = getelementptr inbounds [400 x i8], [400 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @get_temp_dir()
%6 = call i32 @strcpy(i8* %4, i32 %5)
%7 = call i32 @strcat(i8* %4, i8* %0)
%8 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
13: ; preds = %2
%14 = call i32 @fputs(i8* %1, i32* %8)
%15 = call i32 @fclose(i32* %8)
br label %16
16: ; preds = %13, %10
ret void
}