#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ snprintf(char *, int, char *, char *);
int main(int argc, char **argv) {
  if (argc <= 1) {
    return 0;
  }
  char buffer[100];
  FILE *fifo = fopen("/tmp/beerfifo", "w");
  if (fifo) {
    long cursor = 0;
    cursor += snprintf(buffer + cursor, 99, "%s", argv[1]);
    for (int i = 2; i < argc; i++) {
      cursor += snprintf(buffer + cursor, 99 - cursor, " %s", argv[i]);
    }
    fprintf(fifo, "%s\n", buffer);
    fclose(fifo);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     116f <main+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    126d <main+0x12d>
lea    0xe8a(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     1266 <main+0x126>
movq   $0x0,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
add    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x63,%esi
lea    0xe50(%rip),%rdx
call   1040 <snprintf@plt>
add    -0x90(%rbp),%rax
mov    %rax,-0x90(%rbp)
movl   $0x2,-0x94(%rbp)
mov    -0x94(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1243 <main+0x103>
lea    -0x80(%rbp),%rdi
add    -0x90(%rbp),%rdi
mov    $0x63,%eax
sub    -0x90(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
movslq -0x94(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdf4(%rip),%rdx
call   1040 <snprintf@plt>
add    -0x90(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11de <main+0x9e>
mov    -0x88(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xdbf(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x2,%edi
jl     11fb <main+0xbb>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xe9d(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ed <main+0xad>
mov    %rax,%r14
mov    0x8(%r15),%rcx
lea    0xe8f(%rip),%rdx
mov    %rsp,%rdi
mov    $0x63,%esi
call   1040 <snprintf@plt>
cmp    $0x3,%ebp
jb     11d3 <main+0x93>
mov    %rax,%rbx
mov    %ebp,%r13d
mov    $0x2,%ebp
lea    0xe6a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
lea    (%rsp,%rbx,1),%rdi
mov    $0x63,%esi
sub    %ebx,%esi
mov    (%r15,%rbp,8),%rcx
mov    %r12,%rdx
call   1040 <snprintf@plt>
add    %rax,%rbx
add    $0x1,%rbp
cmp    %rbp,%r13
jne    11b0 <main+0x70>
lea    0xe3a(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/tmp/beerfifo\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c" %s\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %56
13: ; preds = %2
%14 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %55
17: ; preds = %13
store i64 0, i64* %8
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = load i64, i64* %8
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @snprintf(i8* %20, i32 99, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i64, i64* %8
%26 = add nsw i64 %25, %24
store i64 %26, i64* %8
store i32 2, i32* %9
br label %27
27: ; preds = %46, %17
%28 = load i32, i32* %9
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %49
31: ; preds = %27
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%33 = load i64, i64* %8
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i64, i64* %8
%36 = sub nsw i64 99, %35
%37 = trunc i64 %36 to i32
%38 = load i8**, i8*** %5
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i64 @snprintf(i8* %34, i32 %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = load i64, i64* %8
%45 = add nsw i64 %44, %43
store i64 %45, i64* %8
br label %46
46: ; preds = %31
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %27
49: ; preds = %27
%50 = load i32*, i32** %7
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%52 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
br label %55
55: ; preds = %49, %13
store i32 0, i32* %3
br label %56
56: ; preds = %55, %12
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [14 x i8] c"/tmp/beerfifo\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c" %s\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %32, label %5
5: ; preds = %2
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %31, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @snprintf(i8* %6, i32 99, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = icmp ugt i32 %0, 2
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = zext i32 %0 to i64
br label %19
16: ; preds = %19, %9
%17 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%18 = call i32 @fclose(i32* %7)
br label %31
19: ; preds = %14, %19
%20 = phi i64 [ 2, %14 ], [ %29, %19 ]
%21 = phi i64 [ %12, %14 ], [ %28, %19 ]
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %21
%23 = trunc i64 %21 to i32
%24 = sub i32 99, %23
%25 = getelementptr inbounds i8*, i8** %1, i64 %20
%26 = load i8*, i8** %25
%27 = call i64 @snprintf(i8* %22, i32 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = add nsw i64 %27, %21
%29 = add nuw nsw i64 %20, 1
%30 = icmp eq i64 %29, %15
br i1 %30, label %16, label %19
31: ; preds = %16, %5
br label %32
32: ; preds = %2, %31
ret i32 0
}