#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int sscanf(char *, char *, int *);
int cmdline_intvar(int argc, char **argv, const char *var) {
  char buf[128];
  int i, out_int;
  snprintf(buf, sizeof(buf), "-D%s=%%i", var);
  for (i = 1; i < argc; i++) {
    if (sscanf(argv[i], buf, &out_int) == 1)
      return out_int;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cmdline_intvar>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x80,%esi
lea    0xeb3(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x1,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11bd <cmdline_intvar+0x9d>
mov    -0x10(%rbp),%rax
movslq -0xa4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0xa0(%rbp),%rsi
lea    -0xa8(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11a4 <cmdline_intvar+0x84>
mov    -0xa8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <cmdline_intvar+0xa4>
jmp    11a9 <cmdline_intvar+0x89>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    115c <cmdline_intvar+0x3c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmdline_intvar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rdx,%rcx
mov    %rsi,%r13
mov    %edi,%ebp
lea    0xec0(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
call   1030 <snprintf@plt>
xor    %r14d,%r14d
cmp    $0x2,%ebp
jl     1195 <cmdline_intvar+0x75>
mov    %ebp,%ebp
mov    $0x1,%ebx
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     1190 <cmdline_intvar+0x70>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <cmdline_intvar+0x50>
jmp    1195 <cmdline_intvar+0x75>
mov    0xc(%rsp),%r14d
mov    %r14d,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"-D%s=%%i\00"
define i32 @cmdline_intvar(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%12 = load i8*, i8** %7
%13 = call i32 @snprintf(i8* %11, i32 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 1, i32* %9
br label %14
14: ; preds = %30, %3
%15 = load i32, i32* %9
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load i8**, i8*** %6
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%25 = call i32 @sscanf(i8* %23, i8* %24, i32* %10)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = load i32, i32* %10
store i32 %28, i32* %4
br label %34
29: ; preds = %18
br label %30
30: ; preds = %29
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %14
33: ; preds = %14
store i32 0, i32* %4
br label %34
34: ; preds = %33, %27
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@.str = [9 x i8] c"-D%s=%%i\00"
define i32 @cmdline_intvar(i32 %0, i8** nocapture %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2)
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %23
10: ; preds = %3
%11 = zext i32 %0 to i64
br label %14
12: ; preds = %14
%13 = icmp eq i64 %20, %11
br i1 %13, label %23, label %14
14: ; preds = %10, %12
%15 = phi i64 [ 1, %10 ], [ %20, %12 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @sscanf(i8* %17, i8* %6, i32* %5)
%19 = icmp eq i32 %18, 1
%20 = add nuw nsw i64 %15, 1
br i1 %19, label %21, label %12
21: ; preds = %14
%22 = load i32, i32* %5
br label %23
23: ; preds = %12, %3, %21
%24 = phi i32 [ %22, %21 ], [ 0, %3 ], [ 0, %12 ]
ret i32 %24
}