#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*/ printf(char *, char const *, long);
void call(const char *syscallname, int *called, int *in, int *limit,
          long orig_eax) {
  *called = 1;
  if (*in) {
    *in = 0;
    printf("%s system call: code %ld\n", syscallname, orig_eax);
    if (*limit > 0)
      (*limit)--;
  } else {
    *in = 1;
  }
}


x86 assembly (clang, -O0):
<call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     117e <call+0x6e>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jle    1179 <call+0x69>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
jmp    1188 <call+0x78>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call>:
push   %rbx
movl   $0x1,(%rsi)
cmpl   $0x0,(%rdx)
je     1147 <call+0x37>
mov    %rcx,%rbx
mov    %rdi,%rax
movl   $0x0,(%rdx)
lea    0xed1(%rip),%rdi
mov    %rax,%rsi
mov    %r8,%rdx
call   1030 <printf@plt>
mov    (%rbx),%eax
test   %eax,%eax
jle    114d <call+0x3d>
add    $0xffffffff,%eax
mov    %eax,(%rbx)
pop    %rbx
ret
movl   $0x1,(%rdx)
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"%s system call: code %ld\0A\00"
define void @call(i8* %0, i32* %1, i32* %2, i32* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i64 %4, i64* %10
%11 = load i32*, i32** %7
store i32 1, i32* %11
%12 = load i32*, i32** %8
%13 = load i32, i32* %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %5
%16 = load i32*, i32** %8
store i32 0, i32* %16
%17 = load i8*, i8** %6
%18 = load i64, i64* %10
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %17, i64 %18)
%20 = load i32*, i32** %9
%21 = load i32, i32* %20
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32*, i32** %9
%25 = load i32, i32* %24
%26 = add nsw i32 %25, -1
store i32 %26, i32* %24
br label %27
27: ; preds = %23, %15
br label %30
28: ; preds = %5
%29 = load i32*, i32** %8
store i32 1, i32* %29
br label %30
30: ; preds = %28, %27
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"%s system call: code %ld\0A\00"
define void @call(i8* %0, i32* nocapture writeonly %1, i32* nocapture %2, i32* nocapture %3, i64 %4) {
store i32 1, i32* %1
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
store i32 0, i32* %2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %4)
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = add nsw i32 %10, -1
store i32 %13, i32* %3
br label %15
14: ; preds = %5
store i32 1, i32* %2
br label %15
15: ; preds = %8, %12, %14
ret void
}