#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ jd_sem_down(int, int);
int /*<<< orphan*/ jd_sem_down2(int, int, int);
int /*<<< orphan*/ jd_sem_lidl2(int, int, int, int);
int /*<<< orphan*/ jd_sem_up2(int, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
void przelew(int *acc_form, int *acc_to, int fd, int semid, int brak_kasy_from,
             int brak_kasy_to, int count, int count_i) {
  int j, i, pid, trans;
  for (j = 0; j < count; j++) {
    switch (pid = fork()) {
    case -1:
      perror("fork error");
      exit(1);
    case 0:
      for (i = 0; i < count_i; i++) {
        usleep(10000);
        while (1) {
          jd_sem_up2(semid, 2, 3);
          printf("przelew %d -> %d\n", *acc_form, *acc_to);
          trans = 100;
          if (*acc_form - 100 >= 0) {
            (*acc_form) -= trans;
            (*acc_to) += trans;
            jd_sem_down(semid, brak_kasy_to);
            break;
          } else {
            printf("brak kasy\n");
            jd_sem_lidl2(semid, 2, 3, brak_kasy_from);
          }
          usleep(10000);
        }
        jd_sem_down2(semid, 3, 2);
      }
      close(fd);
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<przelew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    1318 <przelew+0x178>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %eax,-0x2c(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
sub    $0xffffffff,%eax
je     1204 <przelew+0x64>
jmp    11f4 <przelew+0x54>
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     121a <przelew+0x7a>
jmp    1305 <przelew+0x165>
lea    0xdf5(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    0x18(%rbp),%eax
jge    12f6 <przelew+0x156>
mov    $0x2710,%edi
call   10c0 <usleep@plt>
mov    -0x18(%rbp),%edi
mov    $0x2,%esi
mov    $0x3,%edx
call   1080 <jd_sem_up2@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x64,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sub    $0x64,%eax
cmp    $0x0,%eax
jl     12a4 <przelew+0x104>
mov    -0x30(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x30(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1050 <jd_sem_down@plt>
jmp    12d6 <przelew+0x136>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%ecx
mov    $0x2,%esi
mov    $0x3,%edx
call   1040 <jd_sem_lidl2@plt>
mov    $0x2710,%edi
call   10c0 <usleep@plt>
jmp    1237 <przelew+0x97>
mov    -0x18(%rbp),%edi
mov    $0x3,%esi
mov    $0x2,%edx
call   1030 <jd_sem_down2@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1221 <przelew+0x81>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    130a <przelew+0x16a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cb <przelew+0x2b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<przelew>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0x14(%rsp)
mov    0x50(%rsp),%ebx
test   %ebx,%ebx
jle    11f5 <przelew+0x45>
mov    %r8d,%r12d
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%rbp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     1204 <przelew+0x54>
test   %eax,%eax
je     121a <przelew+0x6a>
add    $0xffffffff,%ebx
jne    11e0 <przelew+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf5(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %r14d,0x10(%rsp)
cmpl   $0x0,0x58(%rsp)
jle    12dc <przelew+0x12c>
lea    0xdda(%rip),%r14
lea    0xde5(%rip),%rbx
movl   $0x0,0xc(%rsp)
jmp    126d <przelew+0xbd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r15d,%edi
mov    $0x2,%esi
mov    $0x3,%edx
mov    %r12d,%ecx
call   1050 <jd_sem_lidl2@plt>
mov    $0x2710,%edi
call   10d0 <usleep@plt>
mov    %r15d,%edi
mov    $0x2,%esi
mov    $0x3,%edx
call   1090 <jd_sem_up2@plt>
mov    0x0(%rbp),%esi
mov    0x0(%r13),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x0(%rbp),%eax
cmp    $0x63,%eax
jle    1250 <przelew+0xa0>
add    $0xffffff9c,%eax
mov    %eax,0x0(%rbp)
addl   $0x64,0x0(%r13)
mov    %r15d,%edi
mov    0x14(%rsp),%esi
call   1060 <jd_sem_down@plt>
mov    %r15d,%edi
mov    $0x3,%esi
mov    $0x2,%edx
call   1030 <jd_sem_down2@plt>
mov    0xc(%rsp),%eax
add    $0x1,%eax
mov    %eax,0xc(%rsp)
cmp    0x58(%rsp),%eax
jne    126d <przelew+0xbd>
mov    0x10(%rsp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"fork error\00"
@.str.1 = [18 x i8] c"przelew %d -> %d\0A\00"
@.str.2 = [11 x i8] c"brak kasy\0A\00"
define void @przelew(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32* %0, i32** %9
store i32* %1, i32** %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
store i32 0, i32* %17
br label %21
21: ; preds = %79, %8
%22 = load i32, i32* %17
%23 = load i32, i32* %15
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %82
25: ; preds = %21
%26 = call i32 (...) @fork()
store i32 %26, i32* %19
switch i32 %26, label %78 [
i32 -1, label %27
i32 0, label %30
]
27: ; preds = %25
%28 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %25
store i32 0, i32* %18
br label %31
31: ; preds = %71, %30
%32 = load i32, i32* %18
%33 = load i32, i32* %16
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %74
35: ; preds = %31
%36 = call i32 @usleep(i32 10000)
br label %37
37: ; preds = %35, %66
%38 = load i32, i32* %12
%39 = call i32 @jd_sem_up2(i32 %38, i32 2, i32 3)
%40 = load i32*, i32** %9
%41 = load i32, i32* %40
%42 = load i32*, i32** %10
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %41, i32 %43)
store i32 100, i32* %20
%45 = load i32*, i32** %9
%46 = load i32, i32* %45
%47 = sub nsw i32 %46, 100
%48 = icmp sge i32 %47, 0
br i1 %48, label %49, label %61
49: ; preds = %37
%50 = load i32, i32* %20
%51 = load i32*, i32** %9
%52 = load i32, i32* %51
%53 = sub nsw i32 %52, %50
store i32 %53, i32* %51
%54 = load i32, i32* %20
%55 = load i32*, i32** %10
%56 = load i32, i32* %55
%57 = add nsw i32 %56, %54
store i32 %57, i32* %55
%58 = load i32, i32* %12
%59 = load i32, i32* %14
%60 = call i32 @jd_sem_down(i32 %58, i32 %59)
br label %68
61: ; preds = %37
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%63 = load i32, i32* %12
%64 = load i32, i32* %13
%65 = call i32 @jd_sem_lidl2(i32 %63, i32 2, i32 3, i32 %64)
br label %66
66: ; preds = %61
%67 = call i32 @usleep(i32 10000)
br label %37
68: ; preds = %49
%69 = load i32, i32* %12
%70 = call i32 @jd_sem_down2(i32 %69, i32 3, i32 2)
br label %71
71: ; preds = %68
%72 = load i32, i32* %18
%73 = add nsw i32 %72, 1
store i32 %73, i32* %18
br label %31
74: ; preds = %31
%75 = load i32, i32* %11
%76 = call i32 @close(i32 %75)
%77 = call i32 @exit(i32 0)
unreachable
78: ; preds = %25
br label %79
79: ; preds = %78
%80 = load i32, i32* %17
%81 = add nsw i32 %80, 1
store i32 %81, i32* %17
br label %21
82: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"fork error\00"
@.str.1 = [18 x i8] c"przelew %d -> %d\0A\00"
@str = [10 x i8] c"brak kasy\00"
define void @przelew(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = icmp sgt i32 %6, 0
br i1 %9, label %10, label %52
10: ; preds = %8, %49
%11 = phi i32 [ %50, %49 ], [ 0, %8 ]
%12 = tail call i32 (...) @fork()
switch i32 %12, label %49 [
i32 -1, label %15
i32 0, label %13
]
13: ; preds = %10
%14 = icmp sgt i32 %7, 0
br i1 %14, label %18, label %46
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %13, %27
%19 = phi i32 [ %34, %27 ], [ 0, %13 ]
%20 = tail call i32 @usleep(i32 10000)
%21 = tail call i32 @jd_sem_up2(i32 %3, i32 2, i32 3)
%22 = load i32, i32* %0
%23 = load i32, i32* %1
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %23)
%25 = load i32, i32* %0
%26 = icmp sgt i32 %25, 99
br i1 %26, label %27, label %36
27: ; preds = %36, %18
%28 = phi i32 [ %25, %18 ], [ %44, %36 ]
%29 = add nsw i32 %28, -100
store i32 %29, i32* %0
%30 = load i32, i32* %1
%31 = add nsw i32 %30, 100
store i32 %31, i32* %1
%32 = tail call i32 @jd_sem_down(i32 %3, i32 %5)
%33 = tail call i32 @jd_sem_down2(i32 %3, i32 3, i32 2)
%34 = add nuw nsw i32 %19, 1
%35 = icmp eq i32 %34, %7
br i1 %35, label %46, label %18
36: ; preds = %18, %36
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%38 = tail call i32 @jd_sem_lidl2(i32 %3, i32 2, i32 3, i32 %4)
%39 = tail call i32 @usleep(i32 10000)
%40 = tail call i32 @jd_sem_up2(i32 %3, i32 2, i32 3)
%41 = load i32, i32* %0
%42 = load i32, i32* %1
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32, i32* %0
%45 = icmp sgt i32 %44, 99
br i1 %45, label %27, label %36
46: ; preds = %27, %13
%47 = tail call i32 @close(i32 %2)
%48 = tail call i32 @exit(i32 0)
unreachable
49: ; preds = %10
%50 = add nuw nsw i32 %11, 1
%51 = icmp eq i32 %50, %6
br i1 %51, label %52, label %10
52: ; preds = %49, %8
ret void
}