#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 */
void *atoi(char *);
int getpid();
int /*<<< orphan*/ printf(char *, int, ...);
int sleep(int);
int main(int argc, char **argv) {
  unsigned i;
  unsigned long dongu_sayisi = -1;
  int bekleme = 0;
  int r;
  int pid = getpid();
  if (argc > 1)
    bekleme = atoi(argv[1]);
  if (argc > 2)
    dongu_sayisi = atoi(argv[2]);
  for (i = 0; i < dongu_sayisi; i++) {
    if (bekleme) {
      r = bekleme;
      while ((r = sleep(r)) > 0)
        printf("[%d] sleep kesildi\n", getpid());
    }
    printf("pid:%d, %d\n", pid, i);
  }
  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)
movq   $0xffffffffffffffff,-0x20(%rbp)
ff
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1189 <main+0x49>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11a4 <main+0x64>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%rax
jae    121f <main+0xdf>
cmpl   $0x0,-0x24(%rbp)
je     11fd <main+0xbd>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1060 <sleep@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jle    11f8 <main+0xb8>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c8 <main+0x88>
jmp    11fd <main+0xbd>
mov    -0x2c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ab <main+0x6b>
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
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r14d
mov    $0xffffffffffffffff,%r12
cmp    $0x2,%ebp
jl     1199 <main+0x59>
mov    0x8(%rbx),%rdi
call   1050 <atoi@plt>
mov    %rax,%r13
cmp    $0x2,%ebp
je     119c <main+0x5c>
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
mov    %rax,%r12
test   %rax,%rax
jne    119c <main+0x5c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
lea    0xe5d(%rip),%rbx
xor    %ebp,%ebp
jmp    11cb <main+0x8b>
nopw   0x0(%rax,%rax,1)
lea    0xe5d(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %rbp,%r12
jbe    1188 <main+0x48>
test   %r13d,%r13d
je     11b0 <main+0x70>
mov    %r13d,%edi
call   1060 <sleep@plt>
test   %eax,%eax
jle    11b0 <main+0x70>
mov    %eax,%r15d
nop
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
call   1060 <sleep@plt>
mov    %eax,%r15d
test   %eax,%eax
jg     11e0 <main+0xa0>
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@.str = [20 x i8] c"[%d] sleep kesildi\0A\00"
@.str.1 = [12 x i8] c"pid:%d, %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 -1, i64* %7
store i32 0, i32* %8
%11 = call i32 (...) @getpid()
store i32 %11, i32* %10
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i8* @atoi(i8* %17)
%19 = ptrtoint i8* %18 to i32
store i32 %19, i32* %8
br label %20
20: ; preds = %14, %2
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 2
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i8* @atoi(i8* %26)
%28 = ptrtoint i8* %27 to i64
store i64 %28, i64* %7
br label %29
29: ; preds = %23, %20
store i32 0, i32* %6
br label %30
30: ; preds = %52, %29
%31 = load i32, i32* %6
%32 = zext i32 %31 to i64
%33 = load i64, i64* %7
%34 = icmp ult i64 %32, %33
br i1 %34, label %35, label %55
35: ; preds = %30
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i32, i32* %8
store i32 %39, i32* %9
br label %40
40: ; preds = %44, %38
%41 = load i32, i32* %9
%42 = call i32 @sleep(i32 %41)
store i32 %42, i32* %9
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = call i32 (...) @getpid()
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %45)
br label %40
47: ; preds = %40
br label %48
48: ; preds = %47, %35
%49 = load i32, i32* %10
%50 = load i32, i32* %6
%51 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %49, i32 %50)
br label %52
52: ; preds = %48
%53 = load i32, i32* %6
%54 = add i32 %53, 1
store i32 %54, i32* %6
br label %30
55: ; preds = %30
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"[%d] sleep kesildi\0A\00"
@.str.1 = [12 x i8] c"pid:%d, %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @getpid()
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %18
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i8* @atoi(i8* %7)
%9 = ptrtoint i8* %8 to i64
%10 = trunc i64 %9 to i32
%11 = icmp eq i32 %0, 2
br i1 %11, label %18, label %12
12: ; preds = %5
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i8* @atoi(i8* %14)
%16 = ptrtoint i8* %15 to i64
%17 = icmp eq i8* %15, null
br i1 %17, label %38, label %18
18: ; preds = %2, %5, %12
%19 = phi i64 [ %16, %12 ], [ -1, %5 ], [ -1, %2 ]
%20 = phi i32 [ %10, %12 ], [ %10, %5 ], [ 0, %2 ]
%21 = icmp eq i32 %20, 0
br label %22
22: ; preds = %18, %33
%23 = phi i32 [ 0, %18 ], [ %35, %33 ]
br i1 %21, label %33, label %24
24: ; preds = %22
%25 = tail call i32 @sleep(i32 %20)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24, %27
%28 = phi i32 [ %31, %27 ], [ %25, %24 ]
%29 = tail call i32 (...) @getpid()
%30 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = tail call i32 @sleep(i32 %28)
%32 = icmp sgt i32 %31, 0
br i1 %32, label %27, label %33
33: ; preds = %27, %24, %22
%34 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %23)
%35 = add i32 %23, 1
%36 = zext i32 %35 to i64
%37 = icmp ugt i64 %19, %36
br i1 %37, label %22, label %38
38: ; preds = %33, %12
ret i32 0
}