main(argc, argv) int argc;
char *argv[];
{
  int semid, i, no_producers;
  struct fifo_buf *buf;
  semid = get_semaphores();
  getseg(&buf);
  if (argc < 2)
    no_producers = 1;
  else
    no_producers = atoi(argv[1]);
  for (i = 0; i < no_producers; i++) {
    if (fork() == 0) {
      producer(semid, buf, i);
      exit(0);
    }
  }
  consumer(semid, buf, no_producers);
  release_ipc_objects();
  exit(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    $0x0,%al
call   1060 <get_semaphores@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x0,%al
call   1040 <getseg@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11c1 <main+0x41>
movl   $0x1,-0x1c(%rbp)
jmp    11d3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x0,%al
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1221 <main+0xa1>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%eax
jne    120e <main+0x8e>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1030 <producer@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    1213 <main+0x93>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11da <main+0x5a>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1070 <consumer@plt>
mov    $0x0,%al
call   1050 <release_ipc_objects@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebx
xor    %eax,%eax
call   1060 <get_semaphores@plt>
mov    %eax,%r14d
mov    %rsp,%rdi
xor    %eax,%eax
call   1040 <getseg@plt>
mov    $0x1,%ebp
cmp    $0x2,%ebx
jl     11bb <main+0x3b>
mov    0x8(%r15),%rdi
xor    %eax,%eax
call   1080 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11d2 <main+0x52>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11f0 <main+0x70>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    11c0 <main+0x40>
mov    (%rsp),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <consumer@plt>
xor    %eax,%eax
call   1050 <release_ipc_objects@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    (%rsp),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <producer@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.fifo_buf = type opaque
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.fifo_buf*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (...) @get_semaphores()
store i32 %10, i32* %6
%11 = call i32 (%struct.fifo_buf**, ...) bitcast (i32 (...)* @getseg to i32 (%struct.fifo_buf**, ...)*)(%struct.fifo_buf** %9)
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %8
br label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %18)
store i32 %19, i32* %8
br label %20
20: ; preds = %15, %14
store i32 0, i32* %7
br label %21
21: ; preds = %34, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = call i32 (...) @fork()
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* %6
%30 = load %struct.fifo_buf*, %struct.fifo_buf** %9
%31 = load i32, i32* %7
%32 = call i32 (i32, %struct.fifo_buf*, i32, ...) bitcast (i32 (...)* @producer to i32 (i32, %struct.fifo_buf*, i32, ...)*)(i32 %29, %struct.fifo_buf* %30, i32 %31)
unreachable
33: ; preds = %25
br label %34
34: ; preds = %33
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %21
37: ; preds = %21
%38 = load i32, i32* %6
%39 = load %struct.fifo_buf*, %struct.fifo_buf** %9
%40 = load i32, i32* %8
%41 = call i32 (i32, %struct.fifo_buf*, i32, ...) bitcast (i32 (...)* @consumer to i32 (i32, %struct.fifo_buf*, i32, ...)*)(i32 %38, %struct.fifo_buf* %39, i32 %40)
%42 = call i32 (...) @release_ipc_objects()
unreachable
}

LLVM IR (-O2):
%struct.fifo_buf = type opaque
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.fifo_buf*
%4 = bitcast %struct.fifo_buf** %3 to i8*
%5 = tail call i32 (...) @get_semaphores()
%6 = call i32 (%struct.fifo_buf**, ...) bitcast (i32 (...)* @getseg to i32 (%struct.fifo_buf**, ...)*)(%struct.fifo_buf** %3)
%7 = icmp slt i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %10)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %2, %8
%14 = phi i32 [ %11, %8 ], [ 1, %2 ]
br label %15
15: ; preds = %13, %22
%16 = phi i32 [ %23, %22 ], [ 0, %13 ]
%17 = call i32 (...) @fork()
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load %struct.fifo_buf*, %struct.fifo_buf** %3
%21 = call i32 (i32, %struct.fifo_buf*, i32, ...) bitcast (i32 (...)* @producer to i32 (i32, %struct.fifo_buf*, i32, ...)*)(i32 %5, %struct.fifo_buf* %20, i32 %16)
unreachable
22: ; preds = %15
%23 = add nuw nsw i32 %16, 1
%24 = icmp eq i32 %23, %14
br i1 %24, label %25, label %15
25: ; preds = %22, %8
%26 = phi i32 [ %11, %8 ], [ %14, %22 ]
%27 = load %struct.fifo_buf*, %struct.fifo_buf** %3
%28 = call i32 (i32, %struct.fifo_buf*, i32, ...) bitcast (i32 (...)* @consumer to i32 (i32, %struct.fifo_buf*, i32, ...)*)(i32 %5, %struct.fifo_buf* %27, i32 %26)
%29 = call i32 (...) @release_ipc_objects()
unreachable
}