#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 uint16_t;
typedef scalar_t__ int8_t;

/* Variables and functions */
scalar_t__ pCT_close(int);
scalar_t__ pCT_init(int, int);
int /*<<< orphan*/ printf(char *, scalar_t__);
scalar_t__ read_geldkarte(int);
int test_ctapi2(char *argv0, int pn, int count) {
  uint16_t ctn = 1;
  int i;
  for (i = 0; i < count; i++) {
    int8_t ret;
    ret = pCT_init(ctn, pn);
    if (ret != 0) {
      printf("Error doing CT_init. (Return code:%d)\n", ret);
      return 3;
    }
    ret = read_geldkarte(ctn);
    if (ret) {
      pCT_close(ctn);
      return ret;
    }
    ret = pCT_close(ctn);
    if (ret) {
      return ret;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_ctapi2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1203 <test_ctapi2+0xc3>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <pCT_init@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11a2 <test_ctapi2+0x62>
mov    -0x28(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    120a <test_ctapi2+0xca>
mov    -0x1c(%rbp),%edi
call   1050 <read_geldkarte@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cd <test_ctapi2+0x8d>
mov    -0x1c(%rbp),%edi
call   1060 <pCT_close@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    120a <test_ctapi2+0xca>
mov    -0x1c(%rbp),%edi
call   1060 <pCT_close@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f0 <test_ctapi2+0xb0>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    120a <test_ctapi2+0xca>
jmp    11f5 <test_ctapi2+0xb5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1160 <test_ctapi2+0x20>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ctapi2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %edx,%edx
jle    11b9 <test_ctapi2+0x79>
mov    %edx,%ebp
mov    %esi,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
mov    %r15d,%esi
call   1040 <pCT_init@plt>
test   %rax,%rax
jne    119a <test_ctapi2+0x5a>
mov    $0x1,%edi
call   1050 <read_geldkarte@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1060 <pCT_close@plt>
test   %rbx,%rbx
jne    11b1 <test_ctapi2+0x71>
test   %rax,%rax
jne    11b6 <test_ctapi2+0x76>
add    $0xffffffff,%ebp
jne    1160 <test_ctapi2+0x20>
jmp    11b9 <test_ctapi2+0x79>
lea    0xe5f(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x3,%r14d
jmp    11b9 <test_ctapi2+0x79>
mov    %ebx,%r14d
jmp    11b9 <test_ctapi2+0x79>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Error doing CT_init. (Return code:%d)\0A\00"
define i32 @test_ctapi2(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %43, %3
%12 = load i32, i32* %9
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %46
15: ; preds = %11
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = call i64 @pCT_init(i32 %16, i32 %17)
store i64 %18, i64* %10
%19 = load i64, i64* %10
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i64, i64* %10
%23 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %22)
store i32 3, i32* %4
br label %47
24: ; preds = %15
%25 = load i32, i32* %8
%26 = call i64 @read_geldkarte(i32 %25)
store i64 %26, i64* %10
%27 = load i64, i64* %10
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32, i32* %8
%31 = call i64 @pCT_close(i32 %30)
%32 = load i64, i64* %10
%33 = trunc i64 %32 to i32
store i32 %33, i32* %4
br label %47
34: ; preds = %24
%35 = load i32, i32* %8
%36 = call i64 @pCT_close(i32 %35)
store i64 %36, i64* %10
%37 = load i64, i64* %10
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i64, i64* %10
%41 = trunc i64 %40 to i32
store i32 %41, i32* %4
br label %47
42: ; preds = %34
br label %43
43: ; preds = %42
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %11
46: ; preds = %11
store i32 0, i32* %4
br label %47
47: ; preds = %46, %39, %29, %21
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@.str = [39 x i8] c"Error doing CT_init. (Return code:%d)\0A\00"
define i32 @test_ctapi2(i8* nocapture readnone %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %7, label %24
5: ; preds = %19
%6 = icmp eq i32 %21, %2
br i1 %6, label %24, label %7
7: ; preds = %3, %5
%8 = phi i32 [ %21, %5 ], [ 0, %3 ]
%9 = tail call i64 @pCT_init(i32 1, i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %9)
br label %24
13: ; preds = %7
%14 = tail call i64 @read_geldkarte(i32 1)
%15 = icmp eq i64 %14, 0
%16 = tail call i64 @pCT_close(i32 1)
br i1 %15, label %19, label %17
17: ; preds = %13
%18 = trunc i64 %14 to i32
br label %24
19: ; preds = %13
%20 = icmp eq i64 %16, 0
%21 = add nuw nsw i32 %8, 1
br i1 %20, label %5, label %22
22: ; preds = %19
%23 = trunc i64 %16 to i32
br label %24
24: ; preds = %5, %22, %3, %17, %11
%25 = phi i32 [ %18, %17 ], [ 3, %11 ], [ %23, %22 ], [ 0, %3 ], [ 0, %5 ]
ret i32 %25
}