#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int mkstemp(char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
scalar_t__ strlen(char const *);
scalar_t__ write(int, char const *, scalar_t__);
char *tmp_file_from_buf(const char *buf) {
  char *template = "/tmp/ohcount_diff_XXXXXXX";
  char *path = strdup(template);
  int fd = mkstemp(path);
  if (write(fd, buf, strlen(buf)) != strlen(buf)) {
    fprintf(stderr, "src/diff.c: Could not write temporary file %s.\n", path);
    exit(1);
  }
  close(fd);
  return path;
}


x86 assembly (clang, -O0):
<tmp_file_from_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <mkstemp@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     1206 <tmp_file_from_buf+0x96>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmp_file_from_buf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe7f(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <mkstemp@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbp
jne    11d0 <tmp_file_from_buf+0x60>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"/tmp/ohcount_diff_XXXXXXX\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"src/diff.c: Could not write temporary file %s.\0A\00"
define i8* @tmp_file_from_buf(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strdup(i8* %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @mkstemp(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = load i8*, i8** %2
%12 = load i8*, i8** %2
%13 = call i64 @strlen(i8* %12)
%14 = call i64 @write(i32 %10, i8* %11, i64 %13)
%15 = load i8*, i8** %2
%16 = call i64 @strlen(i8* %15)
%17 = icmp ne i64 %14, %16
br i1 %17, label %18, label %23
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %4
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %1
%24 = load i32, i32* %5
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %4
ret i8* %26
}

LLVM IR (-O2):
@.str = [26 x i8] c"/tmp/ohcount_diff_XXXXXXX\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"src/diff.c: Could not write temporary file %s.\0A\00"
define i8* @tmp_file_from_buf(i8* nocapture %0) {
%2 = tail call dereferenceable_or_null(26) i8* @strdup(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @mkstemp(i8* %2)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = tail call i64 @write(i32 %3, i8* %0, i64 %4)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = icmp eq i64 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = tail call i32 @close(i32 %3)
ret i8* %2
}