#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *get_as(int, char const *, char const *, char **);
int /*<<< orphan*/ *get_obj(int, char const *, char const *, char **);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int get_as_file(int mode, FILE **out, const char *name,
                const char *input_name) {
  if (name != NULL && ~(mode & (1 << 1))) {
    *out = fopen(name, "w");
    if (*out == NULL) {
      fprintf(stderr, "error: couldn't open file %s: ", name);
      perror(NULL);
      return -1;
    }
  } else if ((mode & (1 << 3)) && (mode & (1 << 1))) {
    char buf[100];
    char *foo = NULL;
    if (get_obj(mode, name, input_name, &foo) == NULL)
      return -1;
    snprintf(buf, 100, "as -g -o %s", foo);
    free(foo);
    *out = popen(buf, "w");
    if (*out == NULL) {
      fprintf(stderr, "error: couldn't open process %s: ", buf);
      perror(NULL);
      return -1;
    }
  } else if (mode & (1 << 3)) {
    *out = stdout;
  } else {
    char *foo = NULL;
    if (get_as(mode, name, input_name, &foo) == NULL)
      return -1;
    *out = fopen(foo, "w");
    if (*out == NULL) {
      fprintf(stderr, "error: couldn't open file %s: ", foo);
      perror(NULL);
      return -1;
    }
    free(foo);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_as_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1212 <get_as_file+0x92>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
xor    $0xffffffff,%eax
cmp    $0x0,%eax
je     1212 <get_as_file+0x92>
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    120d <get_as_file+0x8d>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe0f(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ca <get_as_file+0x24a>
jmp    13c3 <get_as_file+0x243>
mov    -0x8(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     12f4 <get_as_file+0x174>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     12f4 <get_as_file+0x174>
movq   $0x0,-0x98(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x98(%rbp),%rcx
call   10a0 <get_obj@plt>
cmp    $0x0,%rax
jne    1268 <get_as_file+0xe8>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ca <get_as_file+0x24a>
lea    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rcx
mov    $0x64,%esi
lea    0xd9f(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    -0x90(%rbp),%rdi
lea    0xd5f(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12ef <get_as_file+0x16f>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
lea    0xd58(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ca <get_as_file+0x24a>
jmp    13be <get_as_file+0x23e>
mov    -0x8(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1319 <get_as_file+0x199>
mov    0x2cce(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    13b9 <get_as_file+0x239>
movq   $0x0,-0xa0(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0xa0(%rbp),%rcx
call   1040 <get_as@plt>
cmp    $0x0,%rax
jne    1351 <get_as_file+0x1d1>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ca <get_as_file+0x24a>
mov    -0xa0(%rbp),%rdi
lea    0xca1(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    13ad <get_as_file+0x22d>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
mov    -0xa0(%rbp),%rdx
lea    0xc6f(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ca <get_as_file+0x24a>
mov    -0xa0(%rbp),%rdi
call   1030 <free@plt>
jmp    13be <get_as_file+0x23e>
jmp    13c3 <get_as_file+0x243>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_as_file>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r14
test   %rdx,%rdx
je     11db <get_as_file+0x5b>
mov    %rdx,%rbx
lea    0xe67(%rip),%rsi
mov    %rdx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rcx
mov    %rax,(%r14)
xor    %eax,%eax
test   %rcx,%rcx
jne    12df <get_as_file+0x15f>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
jmp    12df <get_as_file+0x15f>
mov    %edi,%eax
not    %eax
test   $0xa,%al
jne    125d <get_as_file+0xdd>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rax
xor    %esi,%esi
mov    %rcx,%rdx
mov    %rax,%rcx
call   10a0 <get_obj@plt>
test   %rax,%rax
je     12da <get_as_file+0x15a>
mov    0x8(%rsp),%rcx
lea    0xe0e(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <snprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0xdca(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
mov    %rax,(%r14)
test   %rax,%rax
jne    12b5 <get_as_file+0x135>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
lea    0x10(%rsp),%rdx
jmp    12ce <get_as_file+0x14e>
test   $0x8,%dil
jne    12a8 <get_as_file+0x128>
movq   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rax
xor    %esi,%esi
mov    %rcx,%rdx
mov    %rax,%rcx
call   1040 <get_as@plt>
test   %rax,%rax
je     12da <get_as_file+0x15a>
mov    0x10(%rsp),%rdi
lea    0xd71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     12b9 <get_as_file+0x139>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
jmp    12b5 <get_as_file+0x135>
mov    0x2d29(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
xor    %eax,%eax
jmp    12df <get_as_file+0x15f>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xd34(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"error: couldn't open file %s: \00"
@.str.2 = [12 x i8] c"as -g -o %s\00"
@.str.3 = [34 x i8] c"error: couldn't open process %s: \00"
@stdout = global i32* null
define i32 @get_as_file(i32 %0, i32** %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [100 x i8]
%11 = alloca i8*
%12 = alloca i8*
store i32 %0, i32* %6
store i32** %1, i32*** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %33
15: ; preds = %4
%16 = load i32, i32* %6
%17 = and i32 %16, 2
%18 = xor i32 %17, -1
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = load i8*, i8** %8
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = load i32**, i32*** %7
store i32* %22, i32** %23
%24 = load i32**, i32*** %7
%25 = load i32*, i32** %24
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %32
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %8
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @perror(i32* null)
store i32 -1, i32* %5
br label %98
32: ; preds = %20
br label %97
33: ; preds = %15, %4
%34 = load i32, i32* %6
%35 = and i32 %34, 8
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %66
37: ; preds = %33
%38 = load i32, i32* %6
%39 = and i32 %38, 2
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %66
41: ; preds = %37
store i8* null, i8** %11
%42 = load i32, i32* %6
%43 = load i8*, i8** %8
%44 = load i8*, i8** %9
%45 = call i32* @get_obj(i32 %42, i8* %43, i8* %44, i8** %11)
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %48
47: ; preds = %41
store i32 -1, i32* %5
br label %98
48: ; preds = %41
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%50 = load i8*, i8** %11
%51 = call i32 @snprintf(i8* %49, i32 100, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %11
%53 = call i32 @free(i8* %52)
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%55 = call i32* @popen(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%56 = load i32**, i32*** %7
store i32* %55, i32** %56
%57 = load i32**, i32*** %7
%58 = load i32*, i32** %57
%59 = icmp eq i32* %58, null
br i1 %59, label %60, label %65
60: ; preds = %48
%61 = load i32, i32* @stderr
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%63 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %62)
%64 = call i32 @perror(i32* null)
store i32 -1, i32* %5
br label %98
65: ; preds = %48
br label %96
66: ; preds = %37, %33
%67 = load i32, i32* %6
%68 = and i32 %67, 8
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %66
%71 = load i32*, i32** @stdout
%72 = load i32**, i32*** %7
store i32* %71, i32** %72
br label %95
73: ; preds = %66
store i8* null, i8** %12
%74 = load i32, i32* %6
%75 = load i8*, i8** %8
%76 = load i8*, i8** %9
%77 = call i32* @get_as(i32 %74, i8* %75, i8* %76, i8** %12)
%78 = icmp eq i32* %77, null
br i1 %78, label %79, label %80
79: ; preds = %73
store i32 -1, i32* %5
br label %98
80: ; preds = %73
%81 = load i8*, i8** %12
%82 = call i32* @fopen(i8* %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%83 = load i32**, i32*** %7
store i32* %82, i32** %83
%84 = load i32**, i32*** %7
%85 = load i32*, i32** %84
%86 = icmp eq i32* %85, null
br i1 %86, label %87, label %92
87: ; preds = %80
%88 = load i32, i32* @stderr
%89 = load i8*, i8** %12
%90 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %89)
%91 = call i32 @perror(i32* null)
store i32 -1, i32* %5
br label %98
92: ; preds = %80
%93 = load i8*, i8** %12
%94 = call i32 @free(i8* %93)
br label %95
95: ; preds = %92, %70
br label %96
96: ; preds = %95, %65
br label %97
97: ; preds = %96, %32
store i32 0, i32* %5
br label %98
98: ; preds = %97, %87, %79, %60, %47, %27
%99 = load i32, i32* %5
ret i32 %99
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"error: couldn't open file %s: \00"
@.str.2 = [12 x i8] c"as -g -o %s\00"
@.str.3 = [34 x i8] c"error: couldn't open process %s: \00"
@stdout = global i32* null
define i32 @get_as_file(i32 %0, i32** nocapture writeonly %1, i8* %2, i8* %3) {
%5 = alloca [100 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = icmp eq i8* %2, null
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %1
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %59
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%15 = tail call i32 @perror(i32* null)
br label %59
16: ; preds = %4
%17 = and i32 %0, 10
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %37
19: ; preds = %16
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%21 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%22 = call i32* @get_obj(i32 %0, i8* null, i8* %3, i8** %6)
%23 = icmp eq i32* %22, null
br i1 %23, label %35, label %24
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = call i32 @snprintf(i8* %20, i32 100, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %6
%28 = call i32 @free(i8* %27)
%29 = call i32* @popen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %1
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%34 = call i32 @perror(i32* null)
br label %35
35: ; preds = %31, %19
br label %59
36: ; preds = %24
br label %59
37: ; preds = %16
%38 = and i32 %0, 8
%39 = icmp eq i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = load i32*, i32** @stdout
store i32* %41, i32** %1
br label %59
42: ; preds = %37
%43 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%44 = call i32* @get_as(i32 %0, i8* null, i8* %3, i8** %7)
%45 = icmp eq i32* %44, null
br i1 %45, label %55, label %46
46: ; preds = %42
%47 = load i8*, i8** %7
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %48, i32** %1
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %56
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %7
%53 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = call i32 @perror(i32* null)
br label %55
55: ; preds = %50, %42
br label %59
56: ; preds = %46
%57 = load i8*, i8** %7
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %9, %40, %36, %56, %55, %35, %12
%60 = phi i32 [ -1, %12 ], [ -1, %35 ], [ -1, %55 ], [ 0, %56 ], [ 0, %36 ], [ 0, %40 ], [ 0, %9 ]
ret i32 %60
}