#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 */
int strlen(char const *);
scalar_t__ write(int, char const *, int);
int write_command(int fd, int argc, char **argv) {
  if (write(fd, "1", 2) <= 0) {
    return -1;
  }
  int i;
  for (i = 0; i < 4; i++) {
    const char *arg = i < argc ? argv[i] : "";
    if (write(fd, arg, strlen(arg) + 1) <= 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<write_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    0xec4(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jg     115c <write_command+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <write_command+0xde>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11f7 <write_command+0xd7>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118e <write_command+0x6e>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
jmp    119e <write_command+0x7e>
lea    0xe6c(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    119e <write_command+0x7e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jg     11e4 <write_command+0xc4>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <write_command+0xde>
jmp    11e9 <write_command+0xc9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1163 <write_command+0x43>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_command>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
lea    0xec9(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
jle    120e <write_command+0xee>
test   %r15d,%r15d
jle    115a <write_command+0x3a>
mov    (%r14),%rbp
jmp    1161 <write_command+0x41>
lea    0xea0(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <write@plt>
test   %rax,%rax
jle    120e <write_command+0xee>
cmp    $0x2,%r15d
jl     118b <write_command+0x6b>
mov    0x8(%r14),%rbp
jmp    1192 <write_command+0x72>
lea    0xe6f(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <write@plt>
test   %rax,%rax
jle    120e <write_command+0xee>
cmp    $0x3,%r15d
jl     11b8 <write_command+0x98>
mov    0x10(%r14),%rbp
jmp    11bf <write_command+0x9f>
lea    0xe42(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <write@plt>
test   %rax,%rax
jle    120e <write_command+0xee>
cmp    $0x4,%r15d
jl     11e5 <write_command+0xc5>
mov    0x18(%r14),%rbp
jmp    11ec <write_command+0xcc>
lea    0xe15(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <write@plt>
xor    %r12d,%r12d
test   %rax,%rax
setle  %r12b
neg    %r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @write_command(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%10 = load i32, i32* %5
%11 = call i64 @write(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
%12 = icmp sle i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %44
14: ; preds = %3
store i32 0, i32* %8
br label %15
15: ; preds = %40, %14
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %43
18: ; preds = %15
%19 = load i32, i32* %8
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i8**, i8*** %7
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
br label %29
28: ; preds = %18
br label %29
29: ; preds = %28, %22
%30 = phi i8* [ %27, %22 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %28 ]
store i8* %30, i8** %9
%31 = load i32, i32* %5
%32 = load i8*, i8** %9
%33 = load i8*, i8** %9
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %34, 1
%36 = call i64 @write(i32 %31, i8* %32, i32 %35)
%37 = icmp sle i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %29
store i32 -1, i32* %4
br label %44
39: ; preds = %29
br label %40
40: ; preds = %39
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %15
43: ; preds = %15
store i32 0, i32* %4
br label %44
44: ; preds = %43, %38, %13
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @write_command(i32 %0, i32 %1, i8** nocapture %2) {
%4 = tail call i64 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
%5 = icmp slt i64 %4, 1
br i1 %5, label %50, label %6
6: ; preds = %3
%7 = icmp sgt i32 %1, 0
br i1 %7, label %42, label %44
8: ; preds = %44
%9 = icmp sgt i32 %1, 1
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = getelementptr inbounds i8*, i8** %2, i64 1
%12 = load i8*, i8** %11
br label %13
13: ; preds = %10, %8
%14 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %8 ]
%15 = tail call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = tail call i64 @write(i32 %0, i8* %14, i32 %16)
%18 = icmp slt i64 %17, 1
br i1 %18, label %50, label %19
19: ; preds = %13
%20 = icmp sgt i32 %1, 2
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %2, i64 2
%23 = load i8*, i8** %22
br label %24
24: ; preds = %21, %19
%25 = phi i8* [ %23, %21 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %19 ]
%26 = tail call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 1
%28 = tail call i64 @write(i32 %0, i8* %25, i32 %27)
%29 = icmp slt i64 %28, 1
br i1 %29, label %50, label %30
30: ; preds = %24
%31 = icmp sgt i32 %1, 3
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = getelementptr inbounds i8*, i8** %2, i64 3
%34 = load i8*, i8** %33
br label %35
35: ; preds = %32, %30
%36 = phi i8* [ %34, %32 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %30 ]
%37 = tail call i32 @strlen(i8* %36)
%38 = add nsw i32 %37, 1
%39 = tail call i64 @write(i32 %0, i8* %36, i32 %38)
%40 = icmp slt i64 %39, 1
%41 = sext i1 %40 to i32
br label %50
42: ; preds = %6
%43 = load i8*, i8** %2
br label %44
44: ; preds = %6, %42
%45 = phi i8* [ %43, %42 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %6 ]
%46 = tail call i32 @strlen(i8* %45)
%47 = add nsw i32 %46, 1
%48 = tail call i64 @write(i32 %0, i8* %45, i32 %47)
%49 = icmp slt i64 %48, 1
br i1 %49, label %50, label %8
50: ; preds = %35, %44, %13, %24, %3
%51 = phi i32 [ -1, %3 ], [ -1, %44 ], [ -1, %13 ], [ -1, %24 ], [ %41, %35 ]
ret i32 %51
}