#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 */
scalar_t__ chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write_simple_dll(char *, int);
int main(int argc, char **argv) {
  char *program_name = argv[0];
  char *output_directory = argv[1];
  int i;
  if (argc < 3) {
    fprintf(stderr, "usage: %s output-directory format [format ...] \n\n",
            program_name);
    fprintf(stderr,
            "format is an objdump-style format string, like pei-i386\n");
    exit(2);
  }
  if (chdir(output_directory) != 0) {
    fprintf(stderr, "error: unable to change directory to %s\n",
            output_directory);
    exit(2);
  }
  for (i = 2; i < argc; i++) {
    char *wanted_format = argv[i];
    if (strcmp("pei-i386", wanted_format) == 0) {
      write_simple_dll("simple-pei-i386.dll", 0x14c);
      write_simple_dll("linux-pei-i386.dll", 0x14c ^ 0x7b79);
    } else if (strcmp("pei-x86-64", wanted_format) == 0) {
      write_simple_dll("simple-pei-x86-64.dll", 0x8664);
      write_simple_dll("linux-pei-x86-64.dll", 0x8664 ^ 0x7b79);
    } else {
      fprintf(stderr, "error: can't handle format %s\n", wanted_format);
      exit(2);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c3 <main+0x73>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     11fb <main+0xab>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12dd <main+0x18d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    125f <main+0x10f>
lea    0xe5e(%rip),%rdi
mov    $0x14c,%esi
call   1030 <write_simple_dll@plt>
lea    0xe61(%rip),%rdi
mov    $0x7a35,%esi
call   1030 <write_simple_dll@plt>
jmp    12ca <main+0x17a>
mov    -0x30(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12a0 <main+0x150>
lea    0xe4f(%rip),%rdi
mov    $0x8664,%esi
call   1030 <write_simple_dll@plt>
lea    0xe54(%rip),%rdi
mov    $0xfd1d,%esi
call   1030 <write_simple_dll@plt>
jmp    12c5 <main+0x175>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
jmp    12ca <main+0x17a>
jmp    12cf <main+0x17f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1202 <main+0xb2>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    1243 <main+0xf3>
mov    %edi,%ebp
mov    0x8(%rbx),%r14
mov    %r14,%rdi
call   1040 <chdir@plt>
test   %rax,%rax
jne    1277 <main+0x127>
mov    %ebp,%r13d
mov    $0x2,%ebp
lea    0xf07(%rip),%r14
lea    0xf51(%rip),%r15
jmp    11cb <main+0x7b>
cs nopw 0x0(%rax,%rax,1)
lea    0xef6(%rip),%rdi
mov    $0x14c,%esi
call   1030 <write_simple_dll@plt>
lea    0xef9(%rip),%rdi
mov    $0x7a35,%esi
call   1030 <write_simple_dll@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     120e <main+0xbe>
mov    (%rbx,%rbp,8),%r12
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11a0 <main+0x50>
lea    0xede(%rip),%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    121f <main+0xcf>
lea    0xed5(%rip),%rdi
mov    $0x8664,%esi
call   1030 <write_simple_dll@plt>
mov    %r15,%rdi
mov    $0xfd1d,%esi
jmp    11bd <main+0x6d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xecb(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    (%rbx),%rdx
mov    0x2d93(%rip),%rbx
mov    (%rbx),%edi
lea    0xdaa(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdcc(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
mov    %r14,%rdx
jmp    1232 <main+0xe2>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"usage: %s output-directory format [format ...] \0A\0A\00"
@.str.1 = [57 x i8] c"format is an objdump-style format string, like pei-i386\0A\00"
@.str.2 = [41 x i8] c"error: unable to change directory to %s\0A\00"
@.str.3 = [9 x i8] c"pei-i386\00"
@.str.4 = [20 x i8] c"simple-pei-i386.dll\00"
@.str.5 = [19 x i8] c"linux-pei-i386.dll\00"
@.str.6 = [11 x i8] c"pei-x86-64\00"
@.str.7 = [22 x i8] c"simple-pei-x86-64.dll\00"
@.str.8 = [21 x i8] c"linux-pei-x86-64.dll\00"
@.str.9 = [31 x i8] c"error: can't handle format %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
store i8* %12, i8** %6
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %7
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %6
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 2)
unreachable
25: ; preds = %2
%26 = load i8*, i8** %7
%27 = call i64 @chdir(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %7
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 2)
unreachable
34: ; preds = %25
store i32 2, i32* %8
br label %35
35: ; preds = %65, %34
%36 = load i32, i32* %8
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %68
39: ; preds = %35
%40 = load i8**, i8*** %5
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
store i8* %44, i8** %9
%45 = load i8*, i8** %9
%46 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %39
%49 = call i32 @write_simple_dll(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 332)
%50 = call i32 @write_simple_dll(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 31285)
br label %64
51: ; preds = %39
%52 = load i8*, i8** %9
%53 = call i64 @strcmp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = call i32 @write_simple_dll(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 34404)
%57 = call i32 @write_simple_dll(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 64797)
br label %63
58: ; preds = %51
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %9
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %60)
%62 = call i32 @exit(i32 2)
unreachable
63: ; preds = %55
br label %64
64: ; preds = %63, %48
br label %65
65: ; preds = %64
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
br label %35
68: ; preds = %35
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"usage: %s output-directory format [format ...] \0A\0A\00"
@.str.1 = [57 x i8] c"format is an objdump-style format string, like pei-i386\0A\00"
@.str.2 = [41 x i8] c"error: unable to change directory to %s\0A\00"
@.str.3 = [9 x i8] c"pei-i386\00"
@.str.4 = [20 x i8] c"simple-pei-i386.dll\00"
@.str.5 = [19 x i8] c"linux-pei-i386.dll\00"
@.str.6 = [11 x i8] c"pei-x86-64\00"
@.str.7 = [22 x i8] c"simple-pei-x86-64.dll\00"
@.str.8 = [21 x i8] c"linux-pei-x86-64.dll\00"
@.str.9 = [31 x i8] c"error: can't handle format %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %7)
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 2)
unreachable
13: ; preds = %2
%14 = tail call i64 @chdir(i8* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = zext i32 %0 to i64
br label %22
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%21 = tail call i32 @exit(i32 2)
unreachable
22: ; preds = %16, %41
%23 = phi i64 [ 2, %16 ], [ %42, %41 ]
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = tail call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = tail call i32 @write_simple_dll(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 332)
%30 = tail call i32 @write_simple_dll(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 31285)
br label %41
31: ; preds = %22
%32 = tail call i64 @strcmp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %25)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = tail call i32 @write_simple_dll(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 34404)
%36 = tail call i32 @write_simple_dll(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 64797)
br label %41
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %25)
%40 = tail call i32 @exit(i32 2)
unreachable
41: ; preds = %34, %28
%42 = add nuw nsw i64 %23, 1
%43 = icmp eq i64 %42, %17
br i1 %43, label %44, label %22
44: ; preds = %41
ret i32 0
}