#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 long long pid_t;

/* Variables and functions */
scalar_t__ dump_string_to_textfile(char const *, char *);
scalar_t__ file_exists(char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, long long);
int dpid_issue(const char *dpid_file, pid_t dpid) {
  char outbuf[128];
  long long int my_pid;
  if (file_exists(dpid_file))
    return (1);
  my_pid = dpid;
  snprintf(outbuf, 128, "%lld\n", my_pid);
  if (dump_string_to_textfile(dpid_file, outbuf) != 0)
    return (2);
  return (0);
}


x86 assembly (clang, -O0):
<dpid_issue>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0x0,%rax
je     1162 <dpid_issue+0x32>
movl   $0x1,-0x4(%rbp)
jmp    11b9 <dpid_issue+0x89>
mov    -0x18(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rcx
mov    $0x80,%esi
lea    0xe79(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1050 <dump_string_to_textfile@plt>
cmp    $0x0,%rax
je     11b2 <dpid_issue+0x82>
movl   $0x2,-0x4(%rbp)
jmp    11b9 <dpid_issue+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dpid_issue>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <file_exists@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1186 <dpid_issue+0x56>
lea    0xea5(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <dump_string_to_textfile@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
add    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%lld\0A\00"
define i32 @dpid_issue(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [128 x i8]
%7 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i8*, i8** %4
%9 = call i64 @file_exists(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %23
12: ; preds = %2
%13 = load i64, i64* %5
store i64 %13, i64* %7
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%15 = load i64, i64* %7
%16 = call i32 @snprintf(i8* %14, i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = load i8*, i8** %4
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%19 = call i64 @dump_string_to_textfile(i8* %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %12
store i32 2, i32* %3
br label %23
22: ; preds = %12
store i32 0, i32* %3
br label %23
23: ; preds = %22, %21, %11
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lld\0A\00"
define i32 @dpid_issue(i8* %0, i64 %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @file_exists(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = call i32 @snprintf(i8* %4, i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %1)
%9 = call i64 @dump_string_to_textfile(i8* %0, i8* %4)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i32 0, i32 2
br label %12
12: ; preds = %7, %2
%13 = phi i32 [ 1, %2 ], [ %11, %7 ]
ret i32 %13
}