#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*/ close_the_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getpid();
int /*<<< orphan*/ print_warning(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int system(char *);
int add_warning(char *fname) {
  FILE *fp;
  char tempfile[512];
  char tempfile1[512];
  char commline[7000];
  sprintf(tempfile, "regtmp1%d", getpid());
  sprintf(tempfile1, "regtmp2%d", getpid());
  if ((fp = fopen(tempfile, "w")) == NULL)
    return (1);
  print_warning(fp, tempfile);
  close_the_file(fp);
  sprintf(commline, "%s %s %s > %s ; %s %s %s ; %s %s ", "/bin/cat", tempfile,
          fname, tempfile1, "/bin/mv", tempfile1, fname, "/bin/rm", tempfile);
  return (system(commline));
}


x86 assembly (clang, -O0):
<add_warning>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x1fc0,%rsp
mov    %rdi,-0x20(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x1fa0(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x1fa0(%rbp),%rdi
mov    %eax,%edx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x430(%rbp),%rax
mov    %rax,-0x1f98(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x1f98(%rbp),%rdi
mov    %eax,%edx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x230(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11f7 <add_warning+0x97>
movl   $0x1,-0x14(%rbp)
jmp    1285 <add_warning+0x125>
mov    -0x28(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1040 <print_warning@plt>
mov    -0x28(%rbp),%rdi
call   1060 <close_the_file@plt>
lea    -0x1f90(%rbp),%rdi
lea    -0x230(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    -0x430(%rbp),%r9
lea    -0x430(%rbp),%rbx
mov    -0x20(%rbp),%r11
lea    -0x230(%rbp),%rax
lea    0xdd4(%rip),%rsi
lea    0xdef(%rip),%rdx
lea    0xdf1(%rip),%r14
lea    0xdf2(%rip),%r10
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x1f90(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1fc0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_warning>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1f58,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe81(%rip),%rsi
lea    0x200(%rsp),%r12
mov    %r12,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <sprintf@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe69(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <sprintf@plt>
lea    0xe5d(%rip),%rsi
mov    %r12,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     122d <add_warning+0xcd>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <print_warning@plt>
mov    %rbx,%rdi
call   1060 <close_the_file@plt>
sub    $0x8,%rsp
lea    0xe64(%rip),%r10
lea    0xe55(%rip),%r11
lea    0xe23(%rip),%rsi
lea    0xe3e(%rip),%rdx
lea    0x408(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rcx
mov    %r14,%r8
mov    %r15,%r9
xor    %eax,%eax
push   %r12
push   %r10
push   %r14
push   %r15
push   %r11
call   1080 <sprintf@plt>
add    $0x30,%rsp
mov    %rbx,%rdi
call   1050 <system@plt>
jmp    1232 <add_warning+0xd2>
mov    $0x1,%eax
add    $0x1f58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"regtmp1%d\00"
@.str.1 = [10 x i8] c"regtmp2%d\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [34 x i8] c"%s %s %s > %s ; %s %s %s ; %s %s \00"
@.str.4 = [9 x i8] c"/bin/cat\00"
@.str.5 = [8 x i8] c"/bin/mv\00"
@.str.6 = [8 x i8] c"/bin/rm\00"
define i32 @add_warning(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca [7000 x i8]
store i8* %0, i8** %3
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = call i32 (...) @getpid()
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = call i32 (...) @getpid()
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %15, i32** %4
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 1, i32* %2
br label %34
18: ; preds = %1
%19 = load i32*, i32** %4
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%21 = call i32 @print_warning(i32* %19, i8* %20)
%22 = load i32*, i32** %4
%23 = call i32 @close_the_file(i32* %22)
%24 = getelementptr inbounds [7000 x i8], [7000 x i8]* %7, i64 0, i64 0
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%26 = load i8*, i8** %3
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%29 = load i8*, i8** %3
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %25, i8* %26, i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %28, i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [7000 x i8], [7000 x i8]* %7, i64 0, i64 0
%33 = call i32 @system(i8* %32)
store i32 %33, i32* %2
br label %34
34: ; preds = %18, %17
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [10 x i8] c"regtmp1%d\00"
@.str.1 = [10 x i8] c"regtmp2%d\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [34 x i8] c"%s %s %s > %s ; %s %s %s ; %s %s \00"
@.str.4 = [9 x i8] c"/bin/cat\00"
@.str.5 = [8 x i8] c"/bin/mv\00"
@.str.6 = [8 x i8] c"/bin/rm\00"
define i32 @add_warning(i8* %0) {
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = alloca [7000 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [7000 x i8], [7000 x i8]* %4, i64 0, i64 0
%8 = tail call i32 (...) @getpid()
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 (...) @getpid()
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %19, label %14
14: ; preds = %1
%15 = call i32 @print_warning(i32* %12, i8* %5)
%16 = call i32 @close_the_file(i32* %12)
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %0, i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %6, i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%18 = call i32 @system(i8* %7)
br label %19
19: ; preds = %1, %14
%20 = phi i32 [ %18, %14 ], [ 1, %1 ]
ret i32 %20
}