#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*/ Message(char *, int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
void WriteJobFile(char *queueDir, int pid, char **progArgs, int nProgArgs) {
  char jobFile[240], pwd[240];
  FILE *fp;
  sprintf(jobFile, "%s/%d", queueDir, pid);
  getcwd(pwd, 240);
  do {
    int _terminate_macro_j;
    for (_terminate_macro_j = 0; (pwd)[_terminate_macro_j];
         _terminate_macro_j++) {
      if ((pwd)[_terminate_macro_j] == '\n') {
        (pwd)[_terminate_macro_j] = '\0';
        break;
      }
    }
  } while (0);
  if ((fp = fopen(jobFile, "w")) != NULL) {
    int i;
    fprintf(fp, "%s\n", pwd);
    for (i = 0; i < nProgArgs; i++) {
      fprintf(fp, "%s ", progArgs[i]);
    }
    fprintf(fp, "\n");
    fclose(fp);
  } else {
    char msg[240];
    sprintf(msg, "Unable to create job file %s", jobFile);
    Message("simq", 3, msg);
  }
}


x86 assembly (clang, -O0):
<WriteJobFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x300,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x200(%rbp),%rdi
mov    $0xf0,%esi
call   1050 <getcwd@plt>
movl   $0x0,-0x20c(%rbp)
movslq -0x20c(%rbp),%rax
cmpb   $0x0,-0x200(%rbp,%rax,1)
je     120a <WriteJobFile+0xaa>
movslq -0x20c(%rbp),%rax
movsbl -0x200(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11f1 <WriteJobFile+0x91>
movslq -0x20c(%rbp),%rax
movb   $0x0,-0x200(%rbp,%rax,1)
jmp    120a <WriteJobFile+0xaa>
jmp    11f6 <WriteJobFile+0x96>
mov    -0x20c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20c(%rbp)
jmp    11b0 <WriteJobFile+0x50>
jmp    120f <WriteJobFile+0xaf>
lea    -0x110(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x208(%rbp)
cmp    $0x0,%rax
je     12c6 <WriteJobFile+0x166>
mov    -0x208(%rbp),%rdi
lea    -0x200(%rbp),%rdx
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x210(%rbp)
mov    -0x210(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12a0 <WriteJobFile+0x140>
mov    -0x208(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x210(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd87(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x210(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x210(%rbp)
jmp    1259 <WriteJobFile+0xf9>
mov    -0x208(%rbp),%rdi
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x208(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12fa <WriteJobFile+0x19a>
lea    -0x300(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x300(%rbp),%rdx
lea    0xd3d(%rip),%rdi
mov    $0x3,%esi
call   1040 <Message@plt>
add    $0x300,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteJobFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2d0,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ecx
mov    %rdi,%rdx
lea    0xe6f(%rip),%rsi
xor    %ebx,%ebx
lea    0xf0(%rsp),%rdi
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rsp,%rdi
mov    $0xf0,%esi
call   1050 <getcwd@plt>
nop
movzbl (%rsp,%rbx,1),%eax
test   %al,%al
je     11c8 <WriteJobFile+0x58>
cmp    $0xa,%al
je     11c2 <WriteJobFile+0x52>
add    $0x1,%rbx
jmp    11b0 <WriteJobFile+0x40>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe37(%rip),%rsi
lea    0xf0(%rsp),%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1241 <WriteJobFile+0xd1>
mov    %rax,%r12
lea    0xe1d(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r14d,%r14d
jle    122a <WriteJobFile+0xba>
mov    %r14d,%ebx
lea    0xe05(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r15,%rbp,8),%rdx
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1210 <WriteJobFile+0xa0>
mov    $0xa,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
jmp    1276 <WriteJobFile+0x106>
lea    0xdc8(%rip),%rsi
lea    0x1e0(%rsp),%rbx
lea    0xf0(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xdc4(%rip),%rdi
mov    $0x3,%esi
mov    %rbx,%rdx
call   1040 <Message@plt>
add    $0x2d0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%d\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [4 x i8] c"%s \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [29 x i8] c"Unable to create job file %s\00"
@.str.6 = [5 x i8] c"simq\00"
define void @WriteJobFile(i8* %0, i32 %1, i8** %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca [240 x i8]
%10 = alloca [240 x i8]
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca [240 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32 %3, i32* %8
%15 = getelementptr inbounds [240 x i8], [240 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17)
%19 = getelementptr inbounds [240 x i8], [240 x i8]* %10, i64 0, i64 0
%20 = call i32 @getcwd(i8* %19, i32 240)
br label %21
21: ; preds = %4
store i32 0, i32* %12
br label %22
22: ; preds = %40, %21
%23 = load i32, i32* %12
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [240 x i8], [240 x i8]* %10, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %43
28: ; preds = %22
%29 = load i32, i32* %12
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [240 x i8], [240 x i8]* %10, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %39
35: ; preds = %28
%36 = load i32, i32* %12
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [240 x i8], [240 x i8]* %10, i64 0, i64 %37
store i8 0, i8* %38
br label %43
39: ; preds = %28
br label %40
40: ; preds = %39
%41 = load i32, i32* %12
%42 = add nsw i32 %41, 1
store i32 %42, i32* %12
br label %22
43: ; preds = %35, %22
br label %44
44: ; preds = %43
%45 = getelementptr inbounds [240 x i8], [240 x i8]* %9, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %46, i32** %11
%47 = icmp ne i32* %46, null
br i1 %47, label %48, label %72
48: ; preds = %44
%49 = load i32*, i32** %11
%50 = getelementptr inbounds [240 x i8], [240 x i8]* %10, i64 0, i64 0
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %50)
store i32 0, i32* %13
br label %52
52: ; preds = %64, %48
%53 = load i32, i32* %13
%54 = load i32, i32* %8
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %67
56: ; preds = %52
%57 = load i32*, i32** %11
%58 = load i8**, i8*** %7
%59 = load i32, i32* %13
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %56
%65 = load i32, i32* %13
%66 = add nsw i32 %65, 1
store i32 %66, i32* %13
br label %52
67: ; preds = %52
%68 = load i32*, i32** %11
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%70 = load i32*, i32** %11
%71 = call i32 @fclose(i32* %70)
br label %78
72: ; preds = %44
%73 = getelementptr inbounds [240 x i8], [240 x i8]* %14, i64 0, i64 0
%74 = getelementptr inbounds [240 x i8], [240 x i8]* %9, i64 0, i64 0
%75 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %74)
%76 = getelementptr inbounds [240 x i8], [240 x i8]* %14, i64 0, i64 0
%77 = call i32 @Message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 3, i8* %76)
br label %78
78: ; preds = %72, %67
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%d\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [4 x i8] c"%s \00"
@.str.5 = [29 x i8] c"Unable to create job file %s\00"
@.str.6 = [5 x i8] c"simq\00"
define void @WriteJobFile(i8* %0, i32 %1, i8** nocapture %2, i32 %3) {
%5 = alloca [240 x i8]
%6 = alloca [240 x i8]
%7 = alloca [240 x i8]
%8 = getelementptr inbounds [240 x i8], [240 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [240 x i8], [240 x i8]* %6, i64 0, i64 0
%10 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%11 = call i32 @getcwd(i8* %9, i32 240)
br label %12
12: ; preds = %19, %4
%13 = phi i64 [ %20, %19 ], [ 0, %4 ]
%14 = getelementptr inbounds [240 x i8], [240 x i8]* %6, i64 0, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %19 [
i8 0, label %21
i8 10, label %16
]
16: ; preds = %12
%17 = and i64 %13, 4294967295
%18 = getelementptr inbounds [240 x i8], [240 x i8]* %6, i64 0, i64 %17
store i8 0, i8* %18
br label %21
19: ; preds = %12
%20 = add nuw i64 %13, 1
br label %12
21: ; preds = %12, %16
%22 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %39, label %24
24: ; preds = %21
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%26 = icmp sgt i32 %3, 0
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = zext i32 %3 to i64
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ 0, %27 ], [ %34, %29 ]
%31 = getelementptr inbounds i8*, i8** %2, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = add nuw nsw i64 %30, 1
%35 = icmp eq i64 %34, %28
br i1 %35, label %36, label %29
36: ; preds = %29, %24
%37 = call i32 @fputc(i32 10, i32* %22)
%38 = call i32 @fclose(i32* %22)
br label %43
39: ; preds = %21
%40 = getelementptr inbounds [240 x i8], [240 x i8]* %7, i64 0, i64 0
%41 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %40, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%42 = call i32 @Message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 3, i8* %40)
br label %43
43: ; preds = %39, %36
ret void
}